mirror of
https://e.coding.net/circlecloud/SEOKeywordSearch.git
synced 2024-11-23 02:18:48 +00:00
增加封IP检测...
This commit is contained in:
parent
be29882c7d
commit
be2b84f56b
630
Frm_Main.Designer.cs
generated
630
Frm_Main.Designer.cs
generated
@ -1,309 +1,321 @@
|
||||
namespace EnAliKeywordSearch
|
||||
{
|
||||
partial class Frm_Main
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows 窗体设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = 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 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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm_Main));
|
||||
this.SearchView = new System.Windows.Forms.DataGridView();
|
||||
this.ResultView = new System.Windows.Forms.DataGridView();
|
||||
this.search = new System.Windows.Forms.Button();
|
||||
this.max = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.state = new System.Windows.Forms.Label();
|
||||
this.saveout = new System.Windows.Forms.Button();
|
||||
this.readin = new System.Windows.Forms.Button();
|
||||
this.openFile = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFile = new System.Windows.Forms.SaveFileDialog();
|
||||
this.clearresult = new System.Windows.Forms.Button();
|
||||
this.clearsearch = new System.Windows.Forms.Button();
|
||||
this.company = 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.keyword = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.公司名称 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.关键词 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.百度r = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.必应r = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.搜狗r = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.查询时间 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
((System.ComponentModel.ISupportInitialize)(this.SearchView)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ResultView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// SearchView
|
||||
//
|
||||
this.SearchView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.SearchView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.company,
|
||||
this.百度s,
|
||||
this.必应s,
|
||||
this.搜狗s,
|
||||
this.keyword});
|
||||
this.SearchView.Location = new System.Drawing.Point(11, 58);
|
||||
this.SearchView.Name = "SearchView";
|
||||
this.SearchView.RowTemplate.Height = 23;
|
||||
this.SearchView.Size = new System.Drawing.Size(850, 200);
|
||||
this.SearchView.TabIndex = 0;
|
||||
//
|
||||
// ResultView
|
||||
//
|
||||
this.ResultView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.ResultView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.公司名称,
|
||||
this.关键词,
|
||||
this.百度r,
|
||||
this.必应r,
|
||||
this.搜狗r,
|
||||
this.查询时间});
|
||||
this.ResultView.Location = new System.Drawing.Point(11, 293);
|
||||
this.ResultView.Name = "ResultView";
|
||||
this.ResultView.RowTemplate.Height = 23;
|
||||
this.ResultView.Size = new System.Drawing.Size(850, 300);
|
||||
this.ResultView.TabIndex = 1;
|
||||
//
|
||||
// search
|
||||
//
|
||||
this.search.Location = new System.Drawing.Point(360, 10);
|
||||
this.search.Name = "search";
|
||||
this.search.Size = new System.Drawing.Size(152, 36);
|
||||
this.search.TabIndex = 2;
|
||||
this.search.Text = "查 询 关 键 词";
|
||||
this.search.UseVisualStyleBackColor = true;
|
||||
this.search.Click += new System.EventHandler(this.search_Click);
|
||||
//
|
||||
// max
|
||||
//
|
||||
this.max.Location = new System.Drawing.Point(663, 10);
|
||||
this.max.Name = "max";
|
||||
this.max.Size = new System.Drawing.Size(83, 21);
|
||||
this.max.TabIndex = 3;
|
||||
this.max.Text = "20";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(592, 13);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(65, 12);
|
||||
this.label1.TabIndex = 7;
|
||||
this.label1.Text = "查询页数: ";
|
||||
//
|
||||
// state
|
||||
//
|
||||
this.state.AutoSize = true;
|
||||
this.state.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.state.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.state.Location = new System.Drawing.Point(98, 267);
|
||||
this.state.Name = "state";
|
||||
this.state.Size = new System.Drawing.Size(37, 14);
|
||||
this.state.TabIndex = 8;
|
||||
this.state.Text = "状态";
|
||||
this.state.TextAlign = System.Drawing.ContentAlignment.TopCenter;
|
||||
//
|
||||
// saveout
|
||||
//
|
||||
this.saveout.Location = new System.Drawing.Point(181, 29);
|
||||
this.saveout.Name = "saveout";
|
||||
this.saveout.Size = new System.Drawing.Size(73, 23);
|
||||
this.saveout.TabIndex = 9;
|
||||
this.saveout.Text = "导出关键词";
|
||||
this.saveout.UseVisualStyleBackColor = true;
|
||||
this.saveout.Click += new System.EventHandler(this.saveout_Click);
|
||||
//
|
||||
// readin
|
||||
//
|
||||
this.readin.Location = new System.Drawing.Point(19, 29);
|
||||
this.readin.Name = "readin";
|
||||
this.readin.Size = new System.Drawing.Size(73, 23);
|
||||
this.readin.TabIndex = 10;
|
||||
this.readin.Text = "导入关键词";
|
||||
this.readin.UseVisualStyleBackColor = true;
|
||||
this.readin.Click += new System.EventHandler(this.readin_Click);
|
||||
//
|
||||
// openFile
|
||||
//
|
||||
this.openFile.FileName = "openFileDialog1";
|
||||
//
|
||||
// clearresult
|
||||
//
|
||||
this.clearresult.Location = new System.Drawing.Point(19, 264);
|
||||
this.clearresult.Name = "clearresult";
|
||||
this.clearresult.Size = new System.Drawing.Size(73, 23);
|
||||
this.clearresult.TabIndex = 11;
|
||||
this.clearresult.Text = "清除结果";
|
||||
this.clearresult.UseVisualStyleBackColor = true;
|
||||
this.clearresult.Click += new System.EventHandler(this.clearresult_Click);
|
||||
//
|
||||
// clearsearch
|
||||
//
|
||||
this.clearsearch.Location = new System.Drawing.Point(100, 29);
|
||||
this.clearsearch.Name = "clearsearch";
|
||||
this.clearsearch.Size = new System.Drawing.Size(73, 23);
|
||||
this.clearsearch.TabIndex = 12;
|
||||
this.clearsearch.Text = "清除关键词";
|
||||
this.clearsearch.UseVisualStyleBackColor = true;
|
||||
this.clearsearch.Click += new System.EventHandler(this.clearsearch_Click);
|
||||
//
|
||||
// company
|
||||
//
|
||||
this.company.HeaderText = "公司网址";
|
||||
this.company.Name = "company";
|
||||
this.company.Width = 150;
|
||||
//
|
||||
// 百度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;
|
||||
//
|
||||
// keyword
|
||||
//
|
||||
this.keyword.HeaderText = "关键词(用英文逗号隔开)";
|
||||
this.keyword.Name = "keyword";
|
||||
this.keyword.Width = 350;
|
||||
//
|
||||
// 公司名称
|
||||
//
|
||||
this.公司名称.HeaderText = "公司网站";
|
||||
this.公司名称.Name = "公司名称";
|
||||
this.公司名称.Width = 150;
|
||||
//
|
||||
// 关键词
|
||||
//
|
||||
this.关键词.HeaderText = "关键词";
|
||||
this.关键词.Name = "关键词";
|
||||
this.关键词.Width = 200;
|
||||
//
|
||||
// 百度r
|
||||
//
|
||||
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
|
||||
this.百度r.DefaultCellStyle = dataGridViewCellStyle4;
|
||||
this.百度r.HeaderText = "百度";
|
||||
this.百度r.Name = "百度r";
|
||||
//
|
||||
// 必应r
|
||||
//
|
||||
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
|
||||
this.必应r.DefaultCellStyle = dataGridViewCellStyle5;
|
||||
this.必应r.HeaderText = "必应";
|
||||
this.必应r.Name = "必应r";
|
||||
//
|
||||
// 搜狗r
|
||||
//
|
||||
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
|
||||
this.搜狗r.DefaultCellStyle = dataGridViewCellStyle6;
|
||||
this.搜狗r.HeaderText = "搜狗";
|
||||
this.搜狗r.Name = "搜狗r";
|
||||
//
|
||||
// 查询时间
|
||||
//
|
||||
this.查询时间.HeaderText = "查询时间";
|
||||
this.查询时间.Name = "查询时间";
|
||||
this.查询时间.Width = 130;
|
||||
//
|
||||
// Frm_Main
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(872, 603);
|
||||
this.Controls.Add(this.clearsearch);
|
||||
this.Controls.Add(this.clearresult);
|
||||
this.Controls.Add(this.readin);
|
||||
this.Controls.Add(this.saveout);
|
||||
this.Controls.Add(this.state);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.max);
|
||||
this.Controls.Add(this.search);
|
||||
this.Controls.Add(this.ResultView);
|
||||
this.Controls.Add(this.SearchView);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "Frm_Main";
|
||||
this.Text = "SEO排名查询软件 2015-7-30";
|
||||
this.Load += new System.EventHandler(this.Frm_Main_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.SearchView)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ResultView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataGridView SearchView;
|
||||
private System.Windows.Forms.DataGridView ResultView;
|
||||
private System.Windows.Forms.Button search;
|
||||
private System.Windows.Forms.TextBox max;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label state;
|
||||
private System.Windows.Forms.Button saveout;
|
||||
private System.Windows.Forms.Button readin;
|
||||
private System.Windows.Forms.OpenFileDialog openFile;
|
||||
private System.Windows.Forms.SaveFileDialog saveFile;
|
||||
private System.Windows.Forms.Button clearresult;
|
||||
private System.Windows.Forms.Button clearsearch;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn company;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 百度s;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 必应s;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 搜狗s;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn keyword;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 公司名称;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 关键词;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 百度r;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 必应r;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 搜狗r;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 查询时间;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace EnAliKeywordSearch
|
||||
{
|
||||
partial class Frm_Main
|
||||
{
|
||||
/// <summary>
|
||||
/// 必需的设计器变量。
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 清理所有正在使用的资源。
|
||||
/// </summary>
|
||||
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows 窗体设计器生成的代码
|
||||
|
||||
/// <summary>
|
||||
/// 设计器支持所需的方法 - 不要
|
||||
/// 使用代码编辑器修改此方法的内容。
|
||||
/// </summary>
|
||||
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 dataGridViewCellStyle2 = 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.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Frm_Main));
|
||||
this.SearchView = 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.百度r = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.必应r = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.搜狗r = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.查询时间 = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.search = new System.Windows.Forms.Button();
|
||||
this.max = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.state = new System.Windows.Forms.Label();
|
||||
this.saveout = new System.Windows.Forms.Button();
|
||||
this.readin = new System.Windows.Forms.Button();
|
||||
this.openFile = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFile = new System.Windows.Forms.SaveFileDialog();
|
||||
this.clearresult = new System.Windows.Forms.Button();
|
||||
this.clearsearch = new System.Windows.Forms.Button();
|
||||
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();
|
||||
((System.ComponentModel.ISupportInitialize)(this.SearchView)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ResultView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// SearchView
|
||||
//
|
||||
this.SearchView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.SearchView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.company,
|
||||
this.keyword,
|
||||
this.百度s,
|
||||
this.必应s,
|
||||
this.搜狗s,
|
||||
this.sum});
|
||||
this.SearchView.Location = new System.Drawing.Point(10, 58);
|
||||
this.SearchView.Name = "SearchView";
|
||||
this.SearchView.RowTemplate.Height = 23;
|
||||
this.SearchView.Size = new System.Drawing.Size(850, 200);
|
||||
this.SearchView.TabIndex = 0;
|
||||
//
|
||||
// ResultView
|
||||
//
|
||||
this.ResultView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.ResultView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.公司名称,
|
||||
this.关键词,
|
||||
this.百度r,
|
||||
this.必应r,
|
||||
this.搜狗r,
|
||||
this.查询时间});
|
||||
this.ResultView.Location = new System.Drawing.Point(11, 293);
|
||||
this.ResultView.Name = "ResultView";
|
||||
this.ResultView.RowTemplate.Height = 23;
|
||||
this.ResultView.Size = new System.Drawing.Size(850, 300);
|
||||
this.ResultView.TabIndex = 1;
|
||||
//
|
||||
// 公司名称
|
||||
//
|
||||
this.公司名称.HeaderText = "公司网站";
|
||||
this.公司名称.Name = "公司名称";
|
||||
this.公司名称.Width = 150;
|
||||
//
|
||||
// 关键词
|
||||
//
|
||||
this.关键词.HeaderText = "关键词";
|
||||
this.关键词.Name = "关键词";
|
||||
this.关键词.Width = 200;
|
||||
//
|
||||
// 百度r
|
||||
//
|
||||
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
|
||||
this.百度r.DefaultCellStyle = dataGridViewCellStyle5;
|
||||
this.百度r.HeaderText = "百度";
|
||||
this.百度r.Name = "百度r";
|
||||
//
|
||||
// 必应r
|
||||
//
|
||||
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
|
||||
this.必应r.DefaultCellStyle = dataGridViewCellStyle6;
|
||||
this.必应r.HeaderText = "必应";
|
||||
this.必应r.Name = "必应r";
|
||||
//
|
||||
// 搜狗r
|
||||
//
|
||||
dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
|
||||
this.搜狗r.DefaultCellStyle = dataGridViewCellStyle7;
|
||||
this.搜狗r.HeaderText = "搜狗";
|
||||
this.搜狗r.Name = "搜狗r";
|
||||
//
|
||||
// 查询时间
|
||||
//
|
||||
this.查询时间.HeaderText = "查询时间";
|
||||
this.查询时间.Name = "查询时间";
|
||||
this.查询时间.Width = 130;
|
||||
//
|
||||
// search
|
||||
//
|
||||
this.search.Location = new System.Drawing.Point(360, 10);
|
||||
this.search.Name = "search";
|
||||
this.search.Size = new System.Drawing.Size(152, 36);
|
||||
this.search.TabIndex = 2;
|
||||
this.search.Text = "查 询 关 键 词";
|
||||
this.search.UseVisualStyleBackColor = true;
|
||||
this.search.Click += new System.EventHandler(this.search_Click);
|
||||
//
|
||||
// max
|
||||
//
|
||||
this.max.Location = new System.Drawing.Point(663, 10);
|
||||
this.max.Name = "max";
|
||||
this.max.Size = new System.Drawing.Size(83, 21);
|
||||
this.max.TabIndex = 3;
|
||||
this.max.Text = "20";
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.AutoSize = true;
|
||||
this.label1.Location = new System.Drawing.Point(592, 13);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(65, 12);
|
||||
this.label1.TabIndex = 7;
|
||||
this.label1.Text = "查询页数: ";
|
||||
//
|
||||
// state
|
||||
//
|
||||
this.state.AutoSize = true;
|
||||
this.state.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.state.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.state.Location = new System.Drawing.Point(98, 267);
|
||||
this.state.Name = "state";
|
||||
this.state.Size = new System.Drawing.Size(37, 14);
|
||||
this.state.TabIndex = 8;
|
||||
this.state.Text = "状态";
|
||||
this.state.TextAlign = System.Drawing.ContentAlignment.TopCenter;
|
||||
//
|
||||
// saveout
|
||||
//
|
||||
this.saveout.Location = new System.Drawing.Point(181, 29);
|
||||
this.saveout.Name = "saveout";
|
||||
this.saveout.Size = new System.Drawing.Size(73, 23);
|
||||
this.saveout.TabIndex = 9;
|
||||
this.saveout.Text = "导出关键词";
|
||||
this.saveout.UseVisualStyleBackColor = true;
|
||||
this.saveout.Click += new System.EventHandler(this.saveout_Click);
|
||||
//
|
||||
// readin
|
||||
//
|
||||
this.readin.Location = new System.Drawing.Point(19, 29);
|
||||
this.readin.Name = "readin";
|
||||
this.readin.Size = new System.Drawing.Size(73, 23);
|
||||
this.readin.TabIndex = 10;
|
||||
this.readin.Text = "导入关键词";
|
||||
this.readin.UseVisualStyleBackColor = true;
|
||||
this.readin.Click += new System.EventHandler(this.readin_Click);
|
||||
//
|
||||
// openFile
|
||||
//
|
||||
this.openFile.FileName = "openFileDialog1";
|
||||
//
|
||||
// clearresult
|
||||
//
|
||||
this.clearresult.Location = new System.Drawing.Point(19, 264);
|
||||
this.clearresult.Name = "clearresult";
|
||||
this.clearresult.Size = new System.Drawing.Size(73, 23);
|
||||
this.clearresult.TabIndex = 11;
|
||||
this.clearresult.Text = "清除结果";
|
||||
this.clearresult.UseVisualStyleBackColor = true;
|
||||
this.clearresult.Click += new System.EventHandler(this.clearresult_Click);
|
||||
//
|
||||
// clearsearch
|
||||
//
|
||||
this.clearsearch.Location = new System.Drawing.Point(100, 29);
|
||||
this.clearsearch.Name = "clearsearch";
|
||||
this.clearsearch.Size = new System.Drawing.Size(73, 23);
|
||||
this.clearsearch.TabIndex = 12;
|
||||
this.clearsearch.Text = "清除关键词";
|
||||
this.clearsearch.UseVisualStyleBackColor = true;
|
||||
this.clearsearch.Click += new System.EventHandler(this.clearsearch_Click);
|
||||
//
|
||||
// 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;
|
||||
//
|
||||
// Frm_Main
|
||||
//
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
this.ClientSize = new System.Drawing.Size(872, 603);
|
||||
this.Controls.Add(this.clearsearch);
|
||||
this.Controls.Add(this.clearresult);
|
||||
this.Controls.Add(this.readin);
|
||||
this.Controls.Add(this.saveout);
|
||||
this.Controls.Add(this.state);
|
||||
this.Controls.Add(this.label1);
|
||||
this.Controls.Add(this.max);
|
||||
this.Controls.Add(this.search);
|
||||
this.Controls.Add(this.ResultView);
|
||||
this.Controls.Add(this.SearchView);
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "Frm_Main";
|
||||
this.Text = "SEO排名查询软件 2015-7-30";
|
||||
this.Load += new System.EventHandler(this.Frm_Main_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.SearchView)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.ResultView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataGridView SearchView;
|
||||
private System.Windows.Forms.DataGridView ResultView;
|
||||
private System.Windows.Forms.Button search;
|
||||
private System.Windows.Forms.TextBox max;
|
||||
private System.Windows.Forms.Label label1;
|
||||
private System.Windows.Forms.Label state;
|
||||
private System.Windows.Forms.Button saveout;
|
||||
private System.Windows.Forms.Button readin;
|
||||
private System.Windows.Forms.OpenFileDialog openFile;
|
||||
private System.Windows.Forms.SaveFileDialog saveFile;
|
||||
private System.Windows.Forms.Button clearresult;
|
||||
private System.Windows.Forms.Button clearsearch;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 公司名称;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 关键词;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 百度r;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 必应r;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 搜狗r;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 查询时间;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn company;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn keyword;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 百度s;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 必应s;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn 搜狗s;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn sum;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
457
Frm_Main.cs
457
Frm_Main.cs
@ -1,212 +1,245 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using AliKeywordSearch;
|
||||
using System.Web;
|
||||
using System.Reflection;
|
||||
|
||||
namespace EnAliKeywordSearch
|
||||
{
|
||||
public partial class Frm_Main : Form
|
||||
{
|
||||
public Frm_Main()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
enum SearchType
|
||||
{
|
||||
[UrlValue("https://www.baidu.com/s?wd={0}&pn={1}0&ie=utf-8")]
|
||||
百度,
|
||||
[UrlValue("http://cn.bing.com/search?q={0}&first={1}1&FORM=PERE1")]
|
||||
必应,
|
||||
[UrlValue("http://www.sogou.com/web?query={0}&page={1}&ie=utf8")]
|
||||
搜狗
|
||||
}
|
||||
//360 Can'tUse url = String.Format("http://www.haosou.com/s?q={0}&pn={1}&client=aff-360daohang&ie=utf-8", HttpUtility.UrlEncode(key), i);
|
||||
//BINGurl = String.Format("http://cn.bing.com/search?q={0}&first={1}1&FORM=PERE1", HttpUtility.UrlEncode(key), i - 1);
|
||||
//搜狗url = String.Format("http://www.sogou.com/web?query={0}&page={1}&ie=utf8", HttpUtility.UrlEncode(key), i);
|
||||
//百度url = String.Format("https://www.baidu.com/s?wd={0}&pn={1}0&ie=utf-8", HttpUtility.UrlEncode(key), i - 1);
|
||||
public class UrlValue : System.Attribute
|
||||
{
|
||||
private string _value;
|
||||
|
||||
public UrlValue(string value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get { return _value; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class UrlEnum
|
||||
{
|
||||
public static string GetUrl(Enum value)
|
||||
{
|
||||
string output = null;
|
||||
Type type = value.GetType();
|
||||
|
||||
FieldInfo fi = type.GetField(value.ToString());
|
||||
UrlValue[] attrs =
|
||||
fi.GetCustomAttributes(typeof(UrlValue),
|
||||
false) as UrlValue[];
|
||||
if (attrs.Length > 0)
|
||||
{
|
||||
output = attrs[0].Value;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void search_Click(object sender, EventArgs e)
|
||||
{
|
||||
search.Enabled = false;
|
||||
state.ForeColor = Color.Black;
|
||||
state.ForeColor = Color.Red;
|
||||
HttpHelper httpHelper = new HttpHelper();
|
||||
foreach (DataGridViewRow item in this.SearchView.Rows)
|
||||
{
|
||||
string cpy = item.Cells["company"].Value == null ? "" : item.Cells["company"].Value.ToString();
|
||||
string keys = item.Cells["keyword"].Value == null ? "" : item.Cells["keyword"].Value.ToString();
|
||||
if (cpy != "" && keys != "")
|
||||
{
|
||||
foreach (string key in keys.Split(','))
|
||||
{
|
||||
if (String.IsNullOrEmpty(key))
|
||||
continue;
|
||||
bool maybe = false;
|
||||
int maxpage = this.ToInt(max.Text);
|
||||
int index = this.ResultView.Rows.Add();
|
||||
this.ResultView.FirstDisplayedScrollingRowIndex = index;
|
||||
this.ResultView.Rows[index].Cells["公司名称"].Value = cpy;
|
||||
this.ResultView.Rows[index].Cells["关键词"].Value = key;
|
||||
state.ForeColor = Color.Black;
|
||||
Application.DoEvents();
|
||||
string pageinfo = string.Empty;
|
||||
foreach (SearchType s in Enum.GetValues(typeof(SearchType)))
|
||||
{
|
||||
if (item.Cells[s.ToString() + "s"].Value == null)
|
||||
item.Cells[s.ToString() + "s"].Value = 0;
|
||||
state.Text = "正在 " + s.ToString() + " 查询 " + cpy + " 的关键词 " + key;
|
||||
for (int i = 1; i <= maxpage; i++)
|
||||
{
|
||||
string url = String.Format(UrlEnum.GetUrl(s), HttpUtility.UrlEncode(key), (s.ToString() == "搜狗" ? i : i - 1));
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Value = "查询第" + i + "页...";
|
||||
Application.DoEvents();
|
||||
string htmldoc = httpHelper.Get(url);
|
||||
if (string.IsNullOrEmpty(htmldoc))
|
||||
{
|
||||
state.ForeColor = Color.Red;
|
||||
state.Text = "关键词 " + key + " 在 " + s.ToString() + " 第 " + i + " 页 网页抓取失败 错误:" + HttpHelper.ErrMsg;
|
||||
maybe = true;
|
||||
continue;
|
||||
}
|
||||
string encodecpy = HttpUtility.HtmlEncode(cpy);
|
||||
if (htmldoc.Contains(encodecpy))
|
||||
{
|
||||
pageinfo = "第" + i + "页";
|
||||
if (i == 1)
|
||||
item.Cells[s.ToString() + "s"].Value = int.Parse(item.Cells[s.ToString() + "s"].Value.ToString()) + 1;
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Style.ForeColor = (i == 1 ? Color.Magenta : Color.Black);
|
||||
break;
|
||||
}
|
||||
if (i == maxpage)
|
||||
{
|
||||
pageinfo = maxpage + "页以后";
|
||||
break;
|
||||
}
|
||||
Application.DoEvents();
|
||||
}
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Value = pageinfo + (maybe ? "(可能不准确)" : "");
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Style.ForeColor = maybe ? Color.Red : this.ResultView.Rows[index].Cells[s.ToString() + "r"].Style.ForeColor;
|
||||
this.ResultView.Rows[index].Cells["查询时间"].Value = DateTime.Now.ToString();
|
||||
Application.DoEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Application.DoEvents();
|
||||
}
|
||||
state.ForeColor = Color.Green;
|
||||
state.Text = "所有关键词查询完成!";
|
||||
search.Enabled = true;
|
||||
}
|
||||
|
||||
private int ToInt(String str)
|
||||
{
|
||||
int s = 0;
|
||||
int.TryParse(str, out s);
|
||||
return s;
|
||||
}
|
||||
|
||||
private void Frm_Main_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
#region 窗体事件
|
||||
private void saveout_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveFileDialog cpm = new SaveFileDialog();
|
||||
cpm.Filter = "查排名数据|*.cpm";
|
||||
if (cpm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
List<string> data = new List<string>();
|
||||
foreach (DataGridViewRow item in this.SearchView.Rows)
|
||||
{
|
||||
string cpy = item.Cells["company"].Value == null ? "" : item.Cells["company"].Value.ToString();
|
||||
string keys = item.Cells["keyword"].Value == null ? "" : item.Cells["keyword"].Value.ToString();
|
||||
if (cpy != "" && keys != "")
|
||||
data.Add(cpy + "|" + keys);
|
||||
}
|
||||
Config cfg = new Config(cpm.FileName);
|
||||
cfg.WriteListToTextFile(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void readin_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog cpm = new OpenFileDialog();
|
||||
cpm.Filter = "查排名数据|*.cpm";
|
||||
if (cpm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Config cfg = new Config(cpm.FileName);
|
||||
List<string> data = cfg.ReadTextFileToList();
|
||||
string cpy = string.Empty;
|
||||
string keys = string.Empty;
|
||||
foreach (string item in data)
|
||||
{
|
||||
string[] str = item.Split('|');
|
||||
if (str.Length == 2)
|
||||
{
|
||||
cpy = str[0];
|
||||
keys = str[1];
|
||||
int index = this.SearchView.Rows.Add();
|
||||
this.SearchView.Rows[index].Cells["company"].Value = cpy;
|
||||
this.SearchView.Rows[index].Cells["keyword"].Value = keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearresult_Click(object sender, EventArgs e)
|
||||
{
|
||||
ResultView.Rows.Clear();
|
||||
}
|
||||
|
||||
private void clearsearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
SearchView.Rows.Clear();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using AliKeywordSearch;
|
||||
using System.Web;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace EnAliKeywordSearch
|
||||
{
|
||||
public partial class Frm_Main : Form
|
||||
{
|
||||
public Frm_Main()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
enum SearchType
|
||||
{
|
||||
[UrlValue("https://www.baidu.com/s?wd={0}&pn={1}0&ie=utf-8")]
|
||||
百度,
|
||||
[UrlValue("http://cn.bing.com/search?q={0}&first={1}1&FORM=PERE1")]
|
||||
必应,
|
||||
[UrlValue("http://www.sogou.com/web?query={0}&page={1}&ie=utf8")]
|
||||
搜狗
|
||||
}
|
||||
//360 Can'tUse url = String.Format("http://www.haosou.com/s?q={0}&pn={1}&client=aff-360daohang&ie=utf-8", HttpUtility.UrlEncode(key), i);
|
||||
//BINGurl = String.Format("http://cn.bing.com/search?q={0}&first={1}1&FORM=PERE1", HttpUtility.UrlEncode(key), i - 1);
|
||||
//搜狗url = String.Format("http://www.sogou.com/web?query={0}&page={1}&ie=utf8", HttpUtility.UrlEncode(key), i);
|
||||
//百度url = String.Format("https://www.baidu.com/s?wd={0}&pn={1}0&ie=utf-8", HttpUtility.UrlEncode(key), i - 1);
|
||||
public class UrlValue : System.Attribute
|
||||
{
|
||||
private string _value;
|
||||
|
||||
public UrlValue(string value)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
|
||||
public string Value
|
||||
{
|
||||
get { return _value; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class UrlEnum
|
||||
{
|
||||
public static string GetUrl(Enum value)
|
||||
{
|
||||
string output = null;
|
||||
Type type = value.GetType();
|
||||
|
||||
FieldInfo fi = type.GetField(value.ToString());
|
||||
UrlValue[] attrs =
|
||||
fi.GetCustomAttributes(typeof(UrlValue),
|
||||
false) as UrlValue[];
|
||||
if (attrs.Length > 0)
|
||||
{
|
||||
output = attrs[0].Value;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void search_Click(object sender, EventArgs e)
|
||||
{
|
||||
search.Enabled = false;
|
||||
state.ForeColor = Color.Black;
|
||||
state.ForeColor = Color.Red;
|
||||
HttpHelper httpHelper = new HttpHelper();
|
||||
foreach (DataGridViewRow item in this.SearchView.Rows)
|
||||
{
|
||||
string cpy = item.Cells["company"].Value == null ? "" : item.Cells["company"].Value.ToString();
|
||||
string keys = item.Cells["keyword"].Value == null ? "" : item.Cells["keyword"].Value.ToString();
|
||||
if (cpy != "" && keys != "")
|
||||
{
|
||||
foreach (string key in keys.Split(','))
|
||||
{
|
||||
if (String.IsNullOrEmpty(key))
|
||||
continue;
|
||||
bool maybe = false;
|
||||
int maxpage = this.ToInt(max.Text);
|
||||
int index = this.ResultView.Rows.Add();
|
||||
this.ResultView.FirstDisplayedScrollingRowIndex = index;
|
||||
this.ResultView.Rows[index].Cells["公司名称"].Value = cpy;
|
||||
this.ResultView.Rows[index].Cells["关键词"].Value = key;
|
||||
state.ForeColor = Color.Black;
|
||||
Application.DoEvents();
|
||||
string pageinfo = string.Empty;
|
||||
foreach (SearchType s in Enum.GetValues(typeof(SearchType)))
|
||||
{
|
||||
if (item.Cells[s.ToString() + "s"].Value == null)
|
||||
item.Cells[s.ToString() + "s"].Value = 0;
|
||||
state.Text = "正在 " + s.ToString() + " 查询 " + cpy + " 的关键词 " + key;
|
||||
for (int i = 1; i <= maxpage; i++)
|
||||
{
|
||||
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 + "页...";
|
||||
Application.DoEvents();
|
||||
string htmldoc = httpHelper.Get(url);
|
||||
if (string.IsNullOrEmpty(htmldoc))
|
||||
{
|
||||
state.ForeColor = Color.Red;
|
||||
state.Text = "关键词 " + key + " 在 " + s.ToString() + " 第 " + i + " 页 网页抓取失败 错误:" + HttpHelper.ErrMsg;
|
||||
maybe = true;
|
||||
continue;
|
||||
}
|
||||
if (htmldoc == "0")
|
||||
{
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Value = "已被屏蔽";
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Style.ForeColor = Color.Red;
|
||||
break;
|
||||
}
|
||||
string cpyencode = HttpUtility.HtmlEncode(cpy);
|
||||
int findindex = htmldoc.IndexOf(cpyencode);
|
||||
if (findindex > 0)
|
||||
{
|
||||
string check = htmldoc.Substring(findindex, 60);
|
||||
while (findindex > 0)
|
||||
{
|
||||
check = htmldoc.Substring(findindex, 60);
|
||||
Console.WriteLine(s.ToString() + " " + i + " " + check);
|
||||
if (!check.Contains("\\/"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
findindex = htmldoc.IndexOf(cpyencode, findindex + 1);
|
||||
}
|
||||
if ((check.Contains("span") || check.Contains("><") || check.Contains(".html") || check.Contains("href") || check.Contains("%")))
|
||||
{
|
||||
pageinfo = "第" + i + "页";
|
||||
if (i == 1)
|
||||
item.Cells[s.ToString() + "s"].Value = int.Parse(item.Cells[s.ToString() + "s"].Value.ToString()) + 1;
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Style.ForeColor = (i == 1 ? Color.Magenta : Color.Black);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == maxpage)
|
||||
{
|
||||
pageinfo = maxpage + "页以后";
|
||||
break;
|
||||
}
|
||||
Application.DoEvents();
|
||||
}
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Value = pageinfo + (maybe ? "(可能不准确)" : "");
|
||||
this.ResultView.Rows[index].Cells[s.ToString() + "r"].Style.ForeColor = maybe ? Color.Red : this.ResultView.Rows[index].Cells[s.ToString() + "r"].Style.ForeColor;
|
||||
this.ResultView.Rows[index].Cells["查询时间"].Value = DateTime.Now.ToString();
|
||||
Application.DoEvents();
|
||||
}
|
||||
Console.WriteLine("==================" + key + "==================");
|
||||
}
|
||||
}
|
||||
if (item.Cells["keyword"].Value != null)
|
||||
{
|
||||
if (item.Cells["sum"].Value == null)
|
||||
item.Cells["sum"].Value = 0;
|
||||
foreach (SearchType s in Enum.GetValues(typeof(SearchType)))
|
||||
{
|
||||
int all = int.Parse(item.Cells["sum"].Value.ToString());
|
||||
int add = int.Parse(item.Cells[s.ToString() + "s"].Value.ToString());
|
||||
item.Cells["sum"].Value = all + add;
|
||||
}
|
||||
}
|
||||
Application.DoEvents();
|
||||
}
|
||||
state.ForeColor = Color.Green;
|
||||
state.Text = "所有关键词查询完成!";
|
||||
search.Enabled = true;
|
||||
}
|
||||
|
||||
private int ToInt(String str)
|
||||
{
|
||||
int s = 0;
|
||||
int.TryParse(str, out s);
|
||||
return s;
|
||||
}
|
||||
|
||||
private void Frm_Main_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
#region 窗体事件
|
||||
private void saveout_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveFileDialog cpm = new SaveFileDialog();
|
||||
cpm.Filter = "查排名数据|*.cpm";
|
||||
if (cpm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
List<string> data = new List<string>();
|
||||
foreach (DataGridViewRow item in this.SearchView.Rows)
|
||||
{
|
||||
string cpy = item.Cells["company"].Value == null ? "" : item.Cells["company"].Value.ToString();
|
||||
string keys = item.Cells["keyword"].Value == null ? "" : item.Cells["keyword"].Value.ToString();
|
||||
if (cpy != "" && keys != "")
|
||||
data.Add(cpy + "|" + keys);
|
||||
}
|
||||
Config cfg = new Config(cpm.FileName);
|
||||
cfg.WriteListToTextFile(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void readin_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog cpm = new OpenFileDialog();
|
||||
cpm.Filter = "查排名数据|*.cpm";
|
||||
if (cpm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
Config cfg = new Config(cpm.FileName);
|
||||
List<string> data = cfg.ReadTextFileToList();
|
||||
string cpy = string.Empty;
|
||||
string keys = string.Empty;
|
||||
foreach (string item in data)
|
||||
{
|
||||
string[] str = item.Split('|');
|
||||
if (str.Length == 2)
|
||||
{
|
||||
cpy = str[0];
|
||||
keys = str[1];
|
||||
int index = this.SearchView.Rows.Add();
|
||||
this.SearchView.Rows[index].Cells["company"].Value = cpy;
|
||||
this.SearchView.Rows[index].Cells["keyword"].Value = keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void clearresult_Click(object sender, EventArgs e)
|
||||
{
|
||||
ResultView.Rows.Clear();
|
||||
}
|
||||
|
||||
private void clearsearch_Click(object sender, EventArgs e)
|
||||
{
|
||||
SearchView.Rows.Clear();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -120,6 +120,9 @@
|
||||
<metadata name="company.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="keyword.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="百度s.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
@ -129,7 +132,7 @@
|
||||
<metadata name="搜狗s.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="keyword.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<metadata name="sum.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="公司名称.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
|
729
HttpHelper.cs
729
HttpHelper.cs
@ -1,364 +1,367 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Authentication;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
namespace EnAliKeywordSearch
|
||||
{
|
||||
public class HttpArgs
|
||||
{
|
||||
public enum HttpMethod
|
||||
{
|
||||
GET,
|
||||
POST
|
||||
}
|
||||
public string Url { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Accept { get; set; }
|
||||
public string Referer { get; set; }
|
||||
public string Cookie { get; set; }
|
||||
public string Data { get; set; }
|
||||
public string UA { get; set; }
|
||||
public HttpMethod Method { get; set; }
|
||||
}
|
||||
|
||||
public class HttpHelper
|
||||
{
|
||||
public static int State = 0;
|
||||
public static string ErrMsg = string.Empty;
|
||||
/// <summary>
|
||||
/// 提交方法
|
||||
/// </summary>
|
||||
#region HttpWebRequest & HttpWebResponse
|
||||
|
||||
/// <summary>
|
||||
/// Get方法
|
||||
/// </summary>
|
||||
/// <param name="geturl">请求地址</param>
|
||||
/// <param name="cookieser">Cookies存储器</param>
|
||||
/// <returns>请求返回的Stream</returns>
|
||||
public string Get(string url)
|
||||
{
|
||||
HttpArgs args = ParseURL(url);
|
||||
args.Method = HttpArgs.HttpMethod.GET;
|
||||
string strhtml = InternalSocketHttp(args);
|
||||
return strhtml;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Post方法
|
||||
/// </summary>
|
||||
/// <param name="posturl">请求地址</param>
|
||||
/// <param name="bytes">Post数据</param>
|
||||
/// <param name="cookieser">Cllkies存储器</param>
|
||||
/// <returns>请求返回的流</returns>
|
||||
public string Post(string url,
|
||||
byte[] bytes,
|
||||
CookieContainer cookies,
|
||||
Encoding encoding)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据Url得到host
|
||||
/// </summary>
|
||||
/// <param name="strUrl">url字符串</param>
|
||||
/// <returns>host字符串</returns>
|
||||
private HttpArgs ParseURL(string strUrl)
|
||||
{
|
||||
HttpArgs args = new HttpArgs();
|
||||
|
||||
args.Host = "";
|
||||
args.Port = 80;
|
||||
args.Referer = "";
|
||||
args.Cookie = "";
|
||||
args.Url = "";
|
||||
args.Accept = "text/html";//,application/xhtml+xml,application/xml,application/json;";
|
||||
args.UA = "Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)";
|
||||
|
||||
//http://www.alibaba.com/products/Egg_Laying_Block_Machine/1.html
|
||||
int iIndex = strUrl.IndexOf(@"//");
|
||||
if (iIndex <= 0)
|
||||
return null;
|
||||
//www.alibaba.com:80/products/Egg_Laying_Block_Machine/1.html
|
||||
string nohttpurl = strUrl.Substring(iIndex + 2);
|
||||
string address = nohttpurl;
|
||||
iIndex = nohttpurl.IndexOf(@"/");
|
||||
if (iIndex > 0)
|
||||
{
|
||||
//www.alibaba.com:80
|
||||
address = nohttpurl.Substring(0, iIndex);
|
||||
args.Url = nohttpurl.Substring(iIndex);
|
||||
}
|
||||
iIndex = nohttpurl.IndexOf(@":");
|
||||
if (iIndex > 0)
|
||||
{
|
||||
string[] tempargs = nohttpurl.Trim().Split(char.Parse(":"));
|
||||
args.Host = tempargs[0];
|
||||
args.Port = int.Parse(tempargs[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//www.alibaba.com:80
|
||||
args.Host = address;
|
||||
args.Port = 80;
|
||||
}
|
||||
return args;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Socket
|
||||
|
||||
string InternalSocketHttp(HttpArgs args)
|
||||
{
|
||||
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
try
|
||||
{
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000);
|
||||
socket.Connect(args.Host, args.Port);
|
||||
if (socket.Connected)
|
||||
{
|
||||
byte[] buff = ParseHttpArgs(args);
|
||||
if (socket.Send(buff) > 0)
|
||||
{
|
||||
List<byte> responseBytes = new List<byte>();
|
||||
byte[] buffer = new byte[1024];
|
||||
int iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);
|
||||
while (iNumber > 0)//使用了Connection: Close 所以判断长度为0 时停止接受
|
||||
{
|
||||
responseBytes.AddRange(new List<byte>(buffer));//添加数据到List
|
||||
iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);//继续接收数据
|
||||
}
|
||||
return ParseResponse(responseBytes.ToArray()/*转换List为数组*/, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrMsg = e.Message;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private string ParseResponse(byte[] responseBytes, HttpArgs args)
|
||||
{
|
||||
string responseStr = Encoding.UTF8.GetString(responseBytes);
|
||||
int splitindex = responseStr.IndexOf("\r\n\r\n");
|
||||
if (splitindex > 0)
|
||||
{
|
||||
string responseHeader = responseStr.Substring(0, splitindex);
|
||||
string responseBody = responseStr.Substring(splitindex + 4);
|
||||
|
||||
if (responseHeader.StartsWith("HTTP/1.1 400 Bad Request"))
|
||||
{
|
||||
State = 400;
|
||||
return string.Empty;
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 404"))
|
||||
{
|
||||
State = 404;
|
||||
return string.Empty;
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 302") || responseHeader.StartsWith("HTTP/1.1 301"))
|
||||
{
|
||||
State = 302;
|
||||
int start = responseHeader.ToUpper().IndexOf("LOCATION");
|
||||
if (start > 0)
|
||||
{
|
||||
string temp = responseHeader.Substring(start, responseHeader.Length - start);
|
||||
string[] sArry = Regex.Split(temp, "\r\n");
|
||||
args.Url = sArry[0].Remove(0, 10);
|
||||
if (args.Url == "")
|
||||
return string.Empty;
|
||||
return InternalSocketHttp(args); //注意:302协议需要重定向
|
||||
}
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 200")) //读取内容
|
||||
{
|
||||
State = 200;
|
||||
DecompressWebPage(ref responseBytes, responseHeader);
|
||||
//转码
|
||||
responseBody = DecodeWebStringByHttpHeader(responseBytes, responseHeader);
|
||||
responseBody = DecodeWebStringByHtmlPageInfo(responseBytes, responseBody);
|
||||
}
|
||||
splitindex = responseBody.IndexOf("\r\n\r\n");
|
||||
if (splitindex > 0)
|
||||
responseBody = responseBody.Substring(splitindex + 4);
|
||||
else
|
||||
responseBody = string.Empty;
|
||||
return responseBody;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
|
||||
/// <summary>
|
||||
/// 解压网页
|
||||
/// </summary>
|
||||
/// <param name="responseBytes">网页字节数组含http头</param>
|
||||
/// <param name="iTotalCount">数组长度</param>
|
||||
/// <param name="strHeader">Http头字符串</param>
|
||||
/// <param name="iStart">网页正文开始位置</param>
|
||||
private void DecompressWebPage(ref byte[] responseBytes, string strHeader)
|
||||
{
|
||||
Regex regZip = new Regex(@"Content-Encoding:\s+gzip[^\n]*\r\n", RegexOptions.IgnoreCase);
|
||||
|
||||
if (regZip.IsMatch(strHeader))
|
||||
{
|
||||
responseBytes = Decompress(responseBytes);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解压gzip网页
|
||||
/// </summary>
|
||||
/// <param name="szSource">压缩过的字符串字节数组</param>
|
||||
/// <returns>解压后的字节数组</returns>
|
||||
private byte[] Decompress(byte[] szSource)
|
||||
{
|
||||
MemoryStream msSource = new MemoryStream(szSource);
|
||||
//DeflateStream 也可以这儿
|
||||
GZipStream stream = new GZipStream(msSource, CompressionMode.Decompress);
|
||||
byte[] szTotal = new byte[40 * 1024];
|
||||
long lTotal = 0;
|
||||
byte[] buffer = new byte[8];
|
||||
int iCount = 0;
|
||||
do
|
||||
{
|
||||
iCount = stream.Read(buffer, 0, 8);
|
||||
if (szTotal.Length <= lTotal + iCount) //放大数组
|
||||
{
|
||||
byte[] temp = new byte[szTotal.Length * 10];
|
||||
szTotal.CopyTo(temp, 0);
|
||||
szTotal = temp;
|
||||
}
|
||||
buffer.CopyTo(szTotal, lTotal);
|
||||
lTotal += iCount;
|
||||
} while (iCount != 0);
|
||||
byte[] szDest = new byte[lTotal];
|
||||
Array.Copy(szTotal, 0, szDest, 0, lTotal);
|
||||
return szDest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据Http头标记里面的字符编码解析字符串
|
||||
/// </summary>
|
||||
/// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param>
|
||||
/// <param name="iTotalCount">网页内容字节数组长度</param>
|
||||
/// <param name="strHeader">http头的字符串</param>
|
||||
/// <returns>转好的字符串</returns>
|
||||
private string DecodeWebStringByHttpHeader(byte[] responseBytes, string strHeader)
|
||||
{
|
||||
string strResponse = "";
|
||||
if (strHeader.Contains("charset=GBK") || strHeader.Contains("charset=gb2312"))
|
||||
{
|
||||
strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes);
|
||||
}
|
||||
else
|
||||
strResponse = Encoding.UTF8.GetString(responseBytes);
|
||||
return strResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据网页meta标记里面的字符编码解析字符串
|
||||
/// </summary>
|
||||
/// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param>
|
||||
/// <param name="iTotalCount">网页内容字节数组长度</param>
|
||||
/// <param name="strResponse">网页内容字符串, 可能已经根据其它转码要求转换过的字符串</param>
|
||||
/// <returns>转好的字符串</returns>
|
||||
private string DecodeWebStringByHtmlPageInfo(byte[] responseBytes, string strResponse)
|
||||
{
|
||||
Regex regGB2312 = new Regex(@"<meta[^>]+Content-Type[^>]+gb2312[^>]*>", RegexOptions.IgnoreCase);
|
||||
Regex regGBK = new Regex(@"<meta[^>]+Content-Type[^>]+gbk[^>]*>", RegexOptions.IgnoreCase);
|
||||
Regex regBig5 = new Regex(@"<meta[^>]+Content-Type[^>]+Big5[^>]*>", RegexOptions.IgnoreCase);
|
||||
if (regGB2312.IsMatch(strResponse) || regGBK.IsMatch(strResponse))
|
||||
strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes);
|
||||
if (regBig5.IsMatch(strResponse))
|
||||
strResponse = Encoding.GetEncoding("Big5").GetString(responseBytes);
|
||||
return strResponse;
|
||||
}
|
||||
|
||||
private byte[] ParseHttpArgs(HttpArgs args)
|
||||
{
|
||||
StringBuilder bulider = new StringBuilder();
|
||||
if (args.Method == HttpArgs.HttpMethod.POST)
|
||||
{
|
||||
bulider.AppendLine(string.Format("POST {0} HTTP/1.1", args.Url));
|
||||
bulider.AppendLine("Content-Type: application/x-www-form-urlencoded");
|
||||
}
|
||||
else
|
||||
{
|
||||
bulider.AppendLine(string.Format("GET {0} HTTP/1.1", args.Url));
|
||||
}
|
||||
|
||||
bulider.AppendLine(string.Format("Host: {0}:{1}", args.Host, args.Port));
|
||||
|
||||
bulider.AppendLine("User-Agent: " + args.UA);
|
||||
//"User-Agent: Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)";Mozilla/5.0 (Windows NT 6.1; IE 9.0)
|
||||
if (!string.IsNullOrEmpty(args.Referer))
|
||||
bulider.AppendLine(string.Format("Referer: {0}", args.Referer));
|
||||
|
||||
//bulider.AppendLine("Connection: close");
|
||||
|
||||
bulider.AppendLine("Connection: Close");
|
||||
|
||||
if (!string.IsNullOrEmpty(args.Accept))
|
||||
bulider.AppendLine(string.Format("Accept: {0}", args.Accept));
|
||||
|
||||
if (!string.IsNullOrEmpty(args.Cookie))
|
||||
bulider.AppendLine(string.Format("Cookie: {0}", args.Cookie));
|
||||
|
||||
if (args.Method == HttpArgs.HttpMethod.POST)
|
||||
{
|
||||
bulider.AppendLine(string.Format("Content-Length: {0}\r\n", Encoding.Default.GetBytes(args.Data).Length));
|
||||
bulider.Append(args.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
bulider.Append("\r\n");
|
||||
}
|
||||
|
||||
string header = bulider.ToString();
|
||||
return Encoding.Default.GetBytes(header);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class MilliTimer
|
||||
{
|
||||
private static double times { get; set; }
|
||||
public static void start()
|
||||
{
|
||||
times = getTotalMilliseconds();
|
||||
}
|
||||
|
||||
public static double getTimes()
|
||||
{
|
||||
return getTotalMilliseconds() - times;
|
||||
}
|
||||
|
||||
|
||||
public static double getTotalMilliseconds()
|
||||
{
|
||||
return DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Authentication;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
namespace EnAliKeywordSearch
|
||||
{
|
||||
public class HttpArgs
|
||||
{
|
||||
public enum HttpMethod
|
||||
{
|
||||
GET,
|
||||
POST
|
||||
}
|
||||
public string Url { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Accept { get; set; }
|
||||
public string Referer { get; set; }
|
||||
public string Cookie { get; set; }
|
||||
public string Data { get; set; }
|
||||
public string UA { get; set; }
|
||||
public HttpMethod Method { get; set; }
|
||||
}
|
||||
|
||||
public class HttpHelper
|
||||
{
|
||||
public static int State = 0;
|
||||
public static string ErrMsg = string.Empty;
|
||||
/// <summary>
|
||||
/// 提交方法
|
||||
/// </summary>
|
||||
#region HttpWebRequest & HttpWebResponse
|
||||
|
||||
/// <summary>
|
||||
/// Get方法
|
||||
/// </summary>
|
||||
/// <param name="geturl">请求地址</param>
|
||||
/// <param name="cookieser">Cookies存储器</param>
|
||||
/// <returns>请求返回的Stream</returns>
|
||||
public string Get(string url)
|
||||
{
|
||||
HttpArgs args = ParseURL(url);
|
||||
args.Method = HttpArgs.HttpMethod.GET;
|
||||
string strhtml = InternalSocketHttp(args);
|
||||
return strhtml;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Post方法
|
||||
/// </summary>
|
||||
/// <param name="posturl">请求地址</param>
|
||||
/// <param name="bytes">Post数据</param>
|
||||
/// <param name="cookieser">Cllkies存储器</param>
|
||||
/// <returns>请求返回的流</returns>
|
||||
public string Post(string url,
|
||||
byte[] bytes,
|
||||
CookieContainer cookies,
|
||||
Encoding encoding)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据Url得到host
|
||||
/// </summary>
|
||||
/// <param name="strUrl">url字符串</param>
|
||||
/// <returns>host字符串</returns>
|
||||
private HttpArgs ParseURL(string strUrl)
|
||||
{
|
||||
HttpArgs args = new HttpArgs();
|
||||
|
||||
args.Host = "";
|
||||
args.Port = 80;
|
||||
args.Referer = "";
|
||||
args.Cookie = "";
|
||||
args.Url = "";
|
||||
args.Accept = "text/html";//,application/xhtml+xml,application/xml,application/json;"
|
||||
|
||||
//args.UA = "Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)";
|
||||
//args.UA = @"Mozilla/5.0 (Linux;u;Android 4.2.2;zh-cn;) AppleWebKit/534.46 (KHTML,like Gecko) Version/5.1 Mobile Safari/10600.6.3 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)";
|
||||
args.UA = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 UBrowser/5.2.2603.31 Safari/537.36";
|
||||
|
||||
//http://www.alibaba.com/products/Egg_Laying_Block_Machine/1.html
|
||||
int iIndex = strUrl.IndexOf(@"//");
|
||||
if (iIndex <= 0)
|
||||
return null;
|
||||
//www.alibaba.com:80/products/Egg_Laying_Block_Machine/1.html
|
||||
string nohttpurl = strUrl.Substring(iIndex + 2);
|
||||
string address = nohttpurl;
|
||||
iIndex = nohttpurl.IndexOf(@"/");
|
||||
if (iIndex > 0)
|
||||
{
|
||||
//www.alibaba.com:80
|
||||
address = nohttpurl.Substring(0, iIndex);
|
||||
args.Url = nohttpurl.Substring(iIndex);
|
||||
}
|
||||
iIndex = nohttpurl.IndexOf(@":");
|
||||
if (iIndex > 0)
|
||||
{
|
||||
string[] tempargs = nohttpurl.Trim().Split(char.Parse(":"));
|
||||
args.Host = tempargs[0];
|
||||
args.Port = int.Parse(tempargs[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//www.alibaba.com:80
|
||||
args.Host = address;
|
||||
args.Port = 80;
|
||||
}
|
||||
return args;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Socket
|
||||
|
||||
string InternalSocketHttp(HttpArgs args)
|
||||
{
|
||||
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
try
|
||||
{
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000);
|
||||
socket.Connect(args.Host, args.Port);
|
||||
if (socket.Connected)
|
||||
{
|
||||
byte[] buff = ParseHttpArgs(args);
|
||||
if (socket.Send(buff) > 0)
|
||||
{
|
||||
List<byte> responseBytes = new List<byte>();
|
||||
byte[] buffer = new byte[1024];
|
||||
int iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);
|
||||
while (iNumber > 0)//使用了Connection: Close 所以判断长度为0 时停止接受
|
||||
{
|
||||
responseBytes.AddRange(new List<byte>(buffer));//添加数据到List
|
||||
iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);//继续接收数据
|
||||
}
|
||||
return ParseResponse(responseBytes.ToArray()/*转换List为数组*/, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ErrMsg = e.Message;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private string ParseResponse(byte[] responseBytes, HttpArgs args)
|
||||
{
|
||||
string responseStr = Encoding.UTF8.GetString(responseBytes);
|
||||
int splitindex = responseStr.IndexOf("\r\n\r\n");
|
||||
if (splitindex > 0)
|
||||
{
|
||||
string responseHeader = responseStr.Substring(0, splitindex);
|
||||
string responseBody = responseStr.Substring(splitindex + 4);
|
||||
|
||||
if (responseHeader.StartsWith("HTTP/1.1 400 Bad Request"))
|
||||
{
|
||||
State = 400;
|
||||
return string.Empty;
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 404"))
|
||||
{
|
||||
State = 404;
|
||||
return string.Empty;
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 302") || responseHeader.StartsWith("HTTP/1.1 301"))
|
||||
{
|
||||
State = 302;
|
||||
int start = responseHeader.ToUpper().IndexOf("LOCATION");
|
||||
if (start > 0)
|
||||
{
|
||||
string temp = responseHeader.Substring(start, responseHeader.Length - start);
|
||||
string[] sArry = Regex.Split(temp, "\r\n");
|
||||
args.Url = sArry[0].Remove(0, 10);
|
||||
if (args.Url == "")
|
||||
return string.Empty;
|
||||
return InternalSocketHttp(args); //注意:302协议需要重定向
|
||||
}
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 200")) //读取内容
|
||||
{
|
||||
State = 200;
|
||||
DecompressWebPage(ref responseBytes, responseHeader);
|
||||
//转码
|
||||
responseBody = DecodeWebStringByHttpHeader(responseBytes, responseHeader);
|
||||
responseBody = DecodeWebStringByHtmlPageInfo(responseBytes, responseBody);
|
||||
}
|
||||
splitindex = responseBody.IndexOf("\r\n\r\n");
|
||||
if (splitindex > 0)
|
||||
responseBody = responseBody.Substring(splitindex + 4);
|
||||
else
|
||||
responseBody = string.Empty;
|
||||
return responseBody;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
|
||||
/// <summary>
|
||||
/// 解压网页
|
||||
/// </summary>
|
||||
/// <param name="responseBytes">网页字节数组含http头</param>
|
||||
/// <param name="iTotalCount">数组长度</param>
|
||||
/// <param name="strHeader">Http头字符串</param>
|
||||
/// <param name="iStart">网页正文开始位置</param>
|
||||
private void DecompressWebPage(ref byte[] responseBytes, string strHeader)
|
||||
{
|
||||
Regex regZip = new Regex(@"Content-Encoding:\s+gzip[^\n]*\r\n", RegexOptions.IgnoreCase);
|
||||
|
||||
if (regZip.IsMatch(strHeader))
|
||||
{
|
||||
responseBytes = Decompress(responseBytes);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解压gzip网页
|
||||
/// </summary>
|
||||
/// <param name="szSource">压缩过的字符串字节数组</param>
|
||||
/// <returns>解压后的字节数组</returns>
|
||||
private byte[] Decompress(byte[] szSource)
|
||||
{
|
||||
MemoryStream msSource = new MemoryStream(szSource);
|
||||
//DeflateStream 也可以这儿
|
||||
GZipStream stream = new GZipStream(msSource, CompressionMode.Decompress);
|
||||
byte[] szTotal = new byte[40 * 1024];
|
||||
long lTotal = 0;
|
||||
byte[] buffer = new byte[8];
|
||||
int iCount = 0;
|
||||
do
|
||||
{
|
||||
iCount = stream.Read(buffer, 0, 8);
|
||||
if (szTotal.Length <= lTotal + iCount) //放大数组
|
||||
{
|
||||
byte[] temp = new byte[szTotal.Length * 10];
|
||||
szTotal.CopyTo(temp, 0);
|
||||
szTotal = temp;
|
||||
}
|
||||
buffer.CopyTo(szTotal, lTotal);
|
||||
lTotal += iCount;
|
||||
} while (iCount != 0);
|
||||
byte[] szDest = new byte[lTotal];
|
||||
Array.Copy(szTotal, 0, szDest, 0, lTotal);
|
||||
return szDest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据Http头标记里面的字符编码解析字符串
|
||||
/// </summary>
|
||||
/// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param>
|
||||
/// <param name="iTotalCount">网页内容字节数组长度</param>
|
||||
/// <param name="strHeader">http头的字符串</param>
|
||||
/// <returns>转好的字符串</returns>
|
||||
private string DecodeWebStringByHttpHeader(byte[] responseBytes, string strHeader)
|
||||
{
|
||||
string strResponse = "";
|
||||
if (strHeader.Contains("charset=GBK") || strHeader.Contains("charset=gb2312"))
|
||||
{
|
||||
strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes);
|
||||
}
|
||||
else
|
||||
strResponse = Encoding.UTF8.GetString(responseBytes);
|
||||
return strResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据网页meta标记里面的字符编码解析字符串
|
||||
/// </summary>
|
||||
/// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param>
|
||||
/// <param name="iTotalCount">网页内容字节数组长度</param>
|
||||
/// <param name="strResponse">网页内容字符串, 可能已经根据其它转码要求转换过的字符串</param>
|
||||
/// <returns>转好的字符串</returns>
|
||||
private string DecodeWebStringByHtmlPageInfo(byte[] responseBytes, string strResponse)
|
||||
{
|
||||
Regex regGB2312 = new Regex(@"<meta[^>]+Content-Type[^>]+gb2312[^>]*>", RegexOptions.IgnoreCase);
|
||||
Regex regGBK = new Regex(@"<meta[^>]+Content-Type[^>]+gbk[^>]*>", RegexOptions.IgnoreCase);
|
||||
Regex regBig5 = new Regex(@"<meta[^>]+Content-Type[^>]+Big5[^>]*>", RegexOptions.IgnoreCase);
|
||||
if (regGB2312.IsMatch(strResponse) || regGBK.IsMatch(strResponse))
|
||||
strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes);
|
||||
if (regBig5.IsMatch(strResponse))
|
||||
strResponse = Encoding.GetEncoding("Big5").GetString(responseBytes);
|
||||
return strResponse;
|
||||
}
|
||||
|
||||
private byte[] ParseHttpArgs(HttpArgs args)
|
||||
{
|
||||
StringBuilder bulider = new StringBuilder();
|
||||
if (args.Method == HttpArgs.HttpMethod.POST)
|
||||
{
|
||||
bulider.AppendLine(string.Format("POST {0} HTTP/1.1", args.Url));
|
||||
bulider.AppendLine("Content-Type: application/x-www-form-urlencoded");
|
||||
}
|
||||
else
|
||||
{
|
||||
bulider.AppendLine(string.Format("GET {0} HTTP/1.1", args.Url));
|
||||
}
|
||||
|
||||
bulider.AppendLine(string.Format("Host: {0}:{1}", args.Host, args.Port));
|
||||
|
||||
bulider.AppendLine("User-Agent: " + args.UA);
|
||||
//"User-Agent: Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)";Mozilla/5.0 (Windows NT 6.1; IE 9.0)
|
||||
if (!string.IsNullOrEmpty(args.Referer))
|
||||
bulider.AppendLine(string.Format("Referer: {0}", args.Referer));
|
||||
|
||||
//bulider.AppendLine("Connection: close");
|
||||
|
||||
bulider.AppendLine("Connection: Close");
|
||||
|
||||
if (!string.IsNullOrEmpty(args.Accept))
|
||||
bulider.AppendLine(string.Format("Accept: {0}", args.Accept));
|
||||
|
||||
if (!string.IsNullOrEmpty(args.Cookie))
|
||||
bulider.AppendLine(string.Format("Cookie: {0}", args.Cookie));
|
||||
|
||||
if (args.Method == HttpArgs.HttpMethod.POST)
|
||||
{
|
||||
bulider.AppendLine(string.Format("Content-Length: {0}\r\n", Encoding.Default.GetBytes(args.Data).Length));
|
||||
bulider.Append(args.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
bulider.Append("\r\n");
|
||||
}
|
||||
|
||||
string header = bulider.ToString();
|
||||
return Encoding.Default.GetBytes(header);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class MilliTimer
|
||||
{
|
||||
private static double times { get; set; }
|
||||
public static void start()
|
||||
{
|
||||
times = getTotalMilliseconds();
|
||||
}
|
||||
|
||||
public static double getTimes()
|
||||
{
|
||||
return getTotalMilliseconds() - times;
|
||||
}
|
||||
|
||||
|
||||
public static double getTotalMilliseconds()
|
||||
{
|
||||
return DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user