网站收录查询代码

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

网站收录查询代码

2011年03月04日星期五下午 2:49

今天做个批量查询百度和google收录的小工具

不知道怎么做想了下就去抓取查询页面然后获取收录总数

效果如下图

导入txt文本文本里面每行一个网址

private void button4_Click(object sender, EventArgs e)

{

openFileDialog1.Filter = "超级文本

(*.txt)|*.txt|(All Files)|*.*|文档|*.rtf ";

if (openFileDialog1.ShowDialog() == DialogResult.OK) {

string s = openFileDialog1.FileName;

openFileDialog1.Dispose();

StreamReader sr = new StreamReader(s);

String line;

while ((line = sr.ReadLine()) != null)

{

DataGridViewRow row = new DataGridViewRow();

//row.Cells.Add(new DataGridCell(

//row.Cells[0].Value = line;

object[] para=new object[3];

para[0]=line;

dataGridView1.Rows.Add(para);

}

sr.Close();

sr.Dispose();

}

}

查询代码

//public delegate string MethodCaller(string name);//定义个代理

///

/// 多线程查询

///

///

///

private void button1_Click(object sender, EventArgs e)

{

for (int i = 0; i < dataGridView1.RowCount; i++)

{

if (dataGridView1.Rows[i].Cells[0].Value != null && dataGridView1.Rows[i].Cells[0].Value.ToString().Trim()!="")

{

string url =

dataGridView1.Rows[i].Cells[0].Value.ToString().Trim();

//MethodCaller mc = new

MethodCaller(getBaiduCount);

//IAsyncResult result = mc.BeginInvoke(url, null, null);//输出参数

//MethodCaller mg = new

MethodCaller(getGoogleCount);

//IAsyncResult result1 = mg.BeginInvoke(url, null, null);

//dataGridView1.Rows[i].Cells[1].Value =

mc.EndInvoke(result);

//dataGridView1.Rows[i].Cells[2].Value =

mg.EndInvoke(result1);

ParameterizedThreadStart ParStart = new ParameterizedThreadStart(getBaiduCount);

Thread myThread = new Thread(ParStart);

object o = (object)(url+"_"+i.ToString()+"_1");

myThread.Start(o);

ParameterizedThreadStart ParStart1 = new ParameterizedThreadStart(getGoogleCount);

Thread myThread1 = new Thread(ParStart1);

object o1 = (object)(url + "_" + i.ToString() + "_2");

myThread1.Start(o1);

//dataGridView1.Rows[i].Cells[1].Value = getBaiduCount(url);

//dataGridView1.Rows[i].Cells[2].Value = getGoogleCount(url);

}

}

}

///

/// google收录查询

///

///

///

public void getGoogleCount(object url)

{

string[] arr = url.ToString().Split('_');

string ss =

WebFunc.GetHtmlEx("/search?hl=zh-CN&newwindow =1&safe=strict&biw=1440&bih=506&q=site%3A"+arr[0]+"&btnG=Google+%E6%9 0%9C%E7%B4%A2&aq=f&aqi=&aql=&oq=" );

string start = "

找到约 ";

if (ss.Contains(start))

{

//start = ss.Substring(ss.IndexOf(start) +

start.Length, 20);

//string result = StringSplit(start, "条结果

")[0].Replace(",", "");

string result = StringSplit(StringSplit(ss, start)[1],