1
0
mirror of https://e.coding.net/circlecloud/SEOKeywordSearch.git synced 2024-11-10 00:08:48 +00:00

增加错误重试功能...

This commit is contained in:
j502647092 2015-07-30 21:18:07 +08:00
parent 2bc2488a9f
commit 43ebf21d35
2 changed files with 86 additions and 54 deletions

126
Frm_Main.Designer.cs generated
View File

@ -28,15 +28,21 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm_Main)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm_Main));
this.SearchView = new System.Windows.Forms.DataGridView(); this.SearchView = new System.Windows.Forms.DataGridView();
this.company = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.keyword = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.s = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.s = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.s = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.sum = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ResultView = new System.Windows.Forms.DataGridView(); this.ResultView = new System.Windows.Forms.DataGridView();
this. = new System.Windows.Forms.DataGridViewTextBoxColumn(); this. = new System.Windows.Forms.DataGridViewTextBoxColumn();
this. = new System.Windows.Forms.DataGridViewTextBoxColumn(); this. = new System.Windows.Forms.DataGridViewTextBoxColumn();
@ -54,12 +60,8 @@
this.saveFile = new System.Windows.Forms.SaveFileDialog(); this.saveFile = new System.Windows.Forms.SaveFileDialog();
this.clearresult = new System.Windows.Forms.Button(); this.clearresult = new System.Windows.Forms.Button();
this.clearsearch = new System.Windows.Forms.Button(); this.clearsearch = new System.Windows.Forms.Button();
this.company = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.label2 = new System.Windows.Forms.Label();
this.keyword = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.retry = new System.Windows.Forms.TextBox();
this.s = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.s = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.s = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.sum = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.SearchView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.SearchView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ResultView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ResultView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -80,6 +82,50 @@
this.SearchView.Size = new System.Drawing.Size(850, 200); this.SearchView.Size = new System.Drawing.Size(850, 200);
this.SearchView.TabIndex = 0; this.SearchView.TabIndex = 0;
// //
// company
//
this.company.HeaderText = "公司网址";
this.company.Name = "company";
this.company.Width = 150;
//
// keyword
//
this.keyword.HeaderText = "关键词(用英文逗号隔开)";
this.keyword.Name = "keyword";
this.keyword.Width = 330;
//
// 百度s
//
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.s.DefaultCellStyle = dataGridViewCellStyle1;
this.s.HeaderText = "百度第一页";
this.s.Name = "百度s";
this.s.Width = 90;
//
// 必应s
//
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.s.DefaultCellStyle = dataGridViewCellStyle2;
this.s.HeaderText = "必应第一页";
this.s.Name = "必应s";
this.s.Width = 90;
//
// 搜狗s
//
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.s.DefaultCellStyle = dataGridViewCellStyle3;
this.s.HeaderText = "搜狗第一页";
this.s.Name = "搜狗s";
this.s.Width = 90;
//
// sum
//
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.sum.DefaultCellStyle = dataGridViewCellStyle4;
this.sum.HeaderText = "总计";
this.sum.Name = "sum";
this.sum.Width = 55;
//
// ResultView // ResultView
// //
this.ResultView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.ResultView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
@ -147,7 +193,7 @@
// //
// max // max
// //
this.max.Location = new System.Drawing.Point(663, 10); this.max.Location = new System.Drawing.Point(663, 4);
this.max.Name = "max"; this.max.Name = "max";
this.max.Size = new System.Drawing.Size(83, 21); this.max.Size = new System.Drawing.Size(83, 21);
this.max.TabIndex = 3; this.max.TabIndex = 3;
@ -156,7 +202,7 @@
// label1 // label1
// //
this.label1.AutoSize = true; this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(592, 13); this.label1.Location = new System.Drawing.Point(592, 7);
this.label1.Name = "label1"; this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 12); this.label1.Size = new System.Drawing.Size(65, 12);
this.label1.TabIndex = 7; this.label1.TabIndex = 7;
@ -218,54 +264,30 @@
this.clearsearch.UseVisualStyleBackColor = true; this.clearsearch.UseVisualStyleBackColor = true;
this.clearsearch.Click += new System.EventHandler(this.clearsearch_Click); this.clearsearch.Click += new System.EventHandler(this.clearsearch_Click);
// //
// company // label2
// //
this.company.HeaderText = "公司网址"; this.label2.AutoSize = true;
this.company.Name = "company"; this.label2.BackColor = System.Drawing.SystemColors.ControlLight;
this.company.Width = 150; this.label2.Location = new System.Drawing.Point(592, 34);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(65, 12);
this.label2.TabIndex = 14;
this.label2.Text = "失败重试: ";
// //
// keyword // retry
// //
this.keyword.HeaderText = "关键词(用英文逗号隔开)"; this.retry.Location = new System.Drawing.Point(663, 31);
this.keyword.Name = "keyword"; this.retry.Name = "retry";
this.keyword.Width = 330; this.retry.Size = new System.Drawing.Size(83, 21);
// this.retry.TabIndex = 13;
// 百度s this.retry.Text = "3";
//
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.s.DefaultCellStyle = dataGridViewCellStyle1;
this.s.HeaderText = "百度第一页";
this.s.Name = "百度s";
this.s.Width = 90;
//
// 必应s
//
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.s.DefaultCellStyle = dataGridViewCellStyle2;
this.s.HeaderText = "必应第一页";
this.s.Name = "必应s";
this.s.Width = 90;
//
// 搜狗s
//
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.s.DefaultCellStyle = dataGridViewCellStyle3;
this.s.HeaderText = "搜狗第一页";
this.s.Name = "搜狗s";
this.s.Width = 90;
//
// sum
//
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.sum.DefaultCellStyle = dataGridViewCellStyle4;
this.sum.HeaderText = "总计";
this.sum.Name = "sum";
this.sum.Width = 55;
// //
// Frm_Main // Frm_Main
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(872, 603); this.ClientSize = new System.Drawing.Size(872, 603);
this.Controls.Add(this.label2);
this.Controls.Add(this.retry);
this.Controls.Add(this.clearsearch); this.Controls.Add(this.clearsearch);
this.Controls.Add(this.clearresult); this.Controls.Add(this.clearresult);
this.Controls.Add(this.readin); this.Controls.Add(this.readin);
@ -315,6 +337,8 @@
private System.Windows.Forms.DataGridViewTextBoxColumn s; private System.Windows.Forms.DataGridViewTextBoxColumn s;
private System.Windows.Forms.DataGridViewTextBoxColumn s; private System.Windows.Forms.DataGridViewTextBoxColumn s;
private System.Windows.Forms.DataGridViewTextBoxColumn sum; private System.Windows.Forms.DataGridViewTextBoxColumn sum;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox retry;
} }
} }

View File

@ -99,17 +99,25 @@ namespace SEOKeywordSearch
{ {
if (item.Cells[s.ToString() + "s"].Value == null) if (item.Cells[s.ToString() + "s"].Value == null)
item.Cells[s.ToString() + "s"].Value = 0; item.Cells[s.ToString() + "s"].Value = 0;
state.ForeColor = Color.Black;
state.Text = "正在 " + s.ToString() + " 查询 " + cpy + " 的关键词 " + key; state.Text = "正在 " + s.ToString() + " 查询 " + cpy + " 的关键词 " + key;
for (int i = 1; i <= maxpage; i++) for (int i = 1; i <= maxpage; i++)
{ {
string url = String.Format(UrlEnum.GetUrl(s), HttpUtility.UrlEncode(key), (s.ToString() == "搜狗" ? i : i - 1));//s搜狗的页面值不同 string url = String.Format(UrlEnum.GetUrl(s), HttpUtility.UrlEncode(key), (s.ToString() == "搜狗" ? i : i - 1));//s搜狗的页面值不同
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Value = "查询第" + i + "..."; this.ResultView.Rows[index].Cells[s.ToString() + "r"].Value = "查询第" + i + "...";
Application.DoEvents(); Application.DoEvents();
for (int k = 1; k < int.Parse(retry.Text); k++)
{
httpHelper.Send(HttpMethod.GET, url); httpHelper.Send(HttpMethod.GET, url);
while (httpHelper.readyState != HttpReadyState.) while (httpHelper.readyState != HttpReadyState.)
{ {
Application.DoEvents(); Application.DoEvents();
} }
if (!(string.IsNullOrEmpty(httpHelper.responseBody) || httpHelper.responseBody.StartsWith("0")))
break;
state.ForeColor = Color.Red;
state.Text = "关键词 " + key + " 在 " + s.ToString() + " 第 " + i + " 页 网页抓取失败 重试第 " + k + " 次";
}
string htmldoc = httpHelper.responseBody; string htmldoc = httpHelper.responseBody;
if (string.IsNullOrEmpty(htmldoc)) if (string.IsNullOrEmpty(htmldoc))
{ {