private void buttonStartGetWeibo_Click(object sender, EventArgs e) { //判断有效条件 if ((!this.checkBoxGetImageWeibo.Checked && !this.checkBoxGetVideoWeibo.Checked) || this.textBoxGetWeibo.Text.Equals("") || this.checkedListBox1.CheckedItems.Count == 0) { return; } //关闭操作功能 this.checkBoxGetImageWeibo.Enabled = false; this.checkBoxGetVideoWeibo.Enabled = false; this.textBoxGetWeibo.Enabled = false; this.buttonStartGetWeibo.Enabled = false; //获取图文微博 if (this.checkBoxGetImageWeibo.Checked) { //获取微博 CookieContainer cookies = (this.panel1.Controls[0] as UserLable).Cookies; List <ImageWeibo> imageWeibos = WeiboOperateTool.GetImageWeibos(this.textBoxGetWeibo.Text, out string oid, cookies); for (int i = 0; i < this.checkedListBox1.Items.Count; i++) { if (this.checkedListBox1.GetItemChecked(i)) { string nickName = this.checkedListBox1.Items[i].ToString(); int StartCount = SqliteTool.GetLaveWeiboCount(SqliteTool.WeiboType.ImageWeibo, nickName); SqliteTool.InsertImageWebos(imageWeibos, nickName); int endCount = SqliteTool.GetLaveWeiboCount(SqliteTool.WeiboType.ImageWeibo, nickName); UserLog.WriteNormalLog(nickName, String.Format("爬取图文微博{0}条", endCount - StartCount), String.Format("被爬取用户ID:{0}", this.textBoxGetWeibo.Text)); string requestStr = DateTime.Now.ToString("yyyy-MM-dd HH:MM:ss") + "\n[" + nickName + "]获取结束:此次共取得图文微博" + (endCount - StartCount).ToString() + "条"; this.richTextBox1.Text = this.richTextBox1.Text + requestStr + "\n"; //uid可以正常获取数据时说明有效,存入数据库 if (endCount - StartCount > 0) { SqliteTool.InsertUidAndOid(this.textBoxGetWeibo.Text, oid, nickName); } } } } //获取视频微博 if (this.checkBoxGetImageWeibo.Checked) { } //重启界面操作 this.checkBoxGetImageWeibo.Enabled = true; this.checkBoxGetVideoWeibo.Enabled = true; this.textBoxGetWeibo.Enabled = true; this.buttonStartGetWeibo.Enabled = true; }
//更新数据库事件 private void UpdateSQLiteEvent(object sender) { List <string> uids = SqliteTool.Get10Uid(((UserLable)sender).DisplayName); foreach (string uid in uids) { int StartCount = SqliteTool.GetLaveWeiboCount(SqliteTool.WeiboType.ImageWeibo, ((UserLable)sender).DisplayName); List <ImageWeibo> imageWeibos = WeiboOperateTool.GetImageWeibos(uid, out string oid, ((UserLable)sender).Cookies); SqliteTool.InsertImageWebos(imageWeibos, ((UserLable)sender).DisplayName); int endCount = SqliteTool.GetLaveWeiboCount(SqliteTool.WeiboType.ImageWeibo, ((UserLable)sender).DisplayName); UserLog.WriteNormalLog(((UserLable)sender).DisplayName, String.Format("后台爬取图文微博{0}条", endCount - StartCount), String.Format("被爬取用户ID:{0}", uid)); } //更新微博显示 ((UserLable)sender).ImageWeiboCount = SqliteTool.GetLaveWeiboCount(SqliteTool.WeiboType.ImageWeibo, ((UserLable)sender).DisplayName).ToString(); ((UserLable)sender).VideoWeiboCount = SqliteTool.GetLaveWeiboCount(SqliteTool.WeiboType.VideoWeibo, ((UserLable)sender).DisplayName).ToString(); }