增加错误重试功能...

master
j502647092 2015-07-30 21:20:42 +08:00
parent 6246442492
commit e143f0a9b2
2 changed files with 34 additions and 4 deletions

25
Frm_Main.Designer.cs generated
View File

@ -50,6 +50,8 @@
this.clearresult = new System.Windows.Forms.Button();
this.clearsearch = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.retry = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.SearchView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ResultView)).BeginInit();
this.SuspendLayout();
@ -130,7 +132,7 @@
//
this.max.Location = new System.Drawing.Point(663, 10);
this.max.Name = "max";
this.max.Size = new System.Drawing.Size(83, 21);
this.max.Size = new System.Drawing.Size(69, 21);
this.max.TabIndex = 3;
this.max.Text = "20";
//
@ -231,10 +233,29 @@
this.label2.TabIndex = 13;
this.label2.Text = "查询类型: ";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(738, 13);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 15;
this.label3.Text = "重试次数: ";
//
// retry
//
this.retry.Location = new System.Drawing.Point(809, 10);
this.retry.Name = "retry";
this.retry.Size = new System.Drawing.Size(36, 21);
this.retry.TabIndex = 14;
this.retry.Text = "3";
//
// Frm_Main
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(872, 603);
this.Controls.Add(this.label3);
this.Controls.Add(this.retry);
this.Controls.Add(this.label2);
this.Controls.Add(this.clearsearch);
this.Controls.Add(this.clearresult);
@ -284,6 +305,8 @@
private System.Windows.Forms.Button clearresult;
private System.Windows.Forms.Button clearsearch;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox retry;
}
}

View File

@ -51,10 +51,17 @@ namespace EnAliKeywordSearch
url = String.Format("http://www.alibaba.com/products/F0/{0}/{1}.html", HttpUtility.UrlEncode(key), i);
else
url = String.Format("http://s.1688.com/selloffer/offer_search.htm?keywords={0}&beginPage={1}", HttpUtility.UrlEncode(key), i);
httpHelper.Send(HttpMethod.GET, url);
while (httpHelper.readyState != HttpReadyState.)
for (int k = 1; k < int.Parse(retry.Text); k++)
{
Application.DoEvents();
httpHelper.Send(HttpMethod.GET, url);
while (httpHelper.readyState != HttpReadyState.)
{
Application.DoEvents();
}
if (!(string.IsNullOrEmpty(httpHelper.responseBody) || httpHelper.responseBody.StartsWith("0")))
break;
state.ForeColor = Color.Red;
state.Text = "关键词 " + key + " 第 " + i + " 页 网页抓取失败 重试第 " + k + " 次";
}
string htmldoc = httpHelper.responseBody;
if (string.IsNullOrEmpty(htmldoc))