C#抓取谷歌的搜索结果 大家好,怎么用C#抓取谷歌的搜索结果,哪个高手有写过呢。谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://blog.csdn.net/lsgy2008/article/details/6308544 做过获取百度的 用的HtmlAgilityPack给你找下代码 private void button10_Click(object sender, EventArgs e) { if (ValidData.IsEmpty(textBox1.Text, "关键字不能为空,请核对!") == false) { textBox2.Focus(); return; } else if (ValidData.IsEmpty(textBox2.Text, "长度不能为空,请核对!") == false) { textBox2.Focus(); return; } else if (ValidData.IsNumber(textBox2.Text, "数量必须为整数") == false) { textBox2.Focus(); return; } if (int.Parse(textBox2.Text) > 100) { MessageBox.Show("数量不能超过100(百度内置上限)", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } string url = "http://www.baidu.com/s?wd=" + textBox1.Text + "&rn=" + int.Parse(textBox2.Text) + ""; HtmlAgilityPack.HtmlDocument hd = GetHtmlDocumentFromLink(url); this.Text = getTitle(hd); MainContent(hd); } public void MainContent(HtmlAgilityPack.HtmlDocument hd) { if (hd == null) return; richTextBox3.Text = ""; //贴吧、新闻、商品搜索、软件 SpecialType(hd); for (int i = 0; i < int.Parse(textBox2.Text)+10; i++) { try { HtmlNode navNode = hd.GetElementbyId(i.ToString()); string allXPath = navNode.XPath + "/tr[1]/td[1]/h3[1]"; string title = hd.DocumentNode.SelectSingleNode(allXPath).InnerText; richTextBox3.AppendText("标题:" + title.Trim() + "\r\n"); ////地址 string adr = hd.DocumentNode.SelectSingleNode(allXPath + "/a[1]").Attributes["href"].Value; richTextBox3.AppendText("地址:" + adr + "\r\n"); //百度快照日期 string pDateXPath = navNode.XPath + "/tr[1]/td[1]/font[1]/span[1]"; string pDate = hd.DocumentNode.SelectSingleNode(pDateXPath).InnerText; if (pDate != string.Empty) { richTextBox3.AppendText("百度快照:" + pDate + "\r\n"); string dataP = Regex.Match(pDate, @"\d{4}([-/])\d{1,2}\1\d{1,2}").Value; richTextBox3.AppendText("快照日期:" + dataP + "\r\n\r\n"); } else richTextBox3.AppendText("\r\n\r\n"); } catch (Exception) { richTextBox3.AppendText("\r\n"); } } } 我现在想抓取Google英国的,可是获取不到html代码,都被屏蔽掉了,不知道该如何是好呢 把图片以二进制形式保存到文本文件中??? C#将一个字符串good good study day day up 反转 杨辉三角的输出问题 如何存储委托链表? ◆GridView插入Checkbox问题◆ 这样有什么意义? 跪求C#开发的小系统.... VC++6.0调用C#编写的组件吗??? 请问了,C#的编译问题 一个比较菜的问题~~不过还是希望大家能帮帮我!:) 三层的增删改查 老师留任务 用windows窗体做个简单的计算器,可以连续计算的,没有头绪,谁可以指导一下我呀
给你找下代码
{
if (ValidData.IsEmpty(textBox1.Text, "关键字不能为空,请核对!") == false) { textBox2.Focus(); return; }
else if (ValidData.IsEmpty(textBox2.Text, "长度不能为空,请核对!") == false) { textBox2.Focus(); return; }
else if (ValidData.IsNumber(textBox2.Text, "数量必须为整数") == false) { textBox2.Focus(); return; } if (int.Parse(textBox2.Text) > 100)
{
MessageBox.Show("数量不能超过100(百度内置上限)", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
} string url = "http://www.baidu.com/s?wd=" + textBox1.Text + "&rn=" + int.Parse(textBox2.Text) + "";
HtmlAgilityPack.HtmlDocument hd = GetHtmlDocumentFromLink(url); this.Text = getTitle(hd);
MainContent(hd);
}
public void MainContent(HtmlAgilityPack.HtmlDocument hd)
{
if (hd == null)
return;
richTextBox3.Text = "";
//贴吧、新闻、商品搜索、软件
SpecialType(hd); for (int i = 0; i < int.Parse(textBox2.Text)+10; i++)
{
try
{
HtmlNode navNode = hd.GetElementbyId(i.ToString());
string allXPath = navNode.XPath + "/tr[1]/td[1]/h3[1]";
string title = hd.DocumentNode.SelectSingleNode(allXPath).InnerText;
richTextBox3.AppendText("标题:" + title.Trim() + "\r\n");
////地址
string adr = hd.DocumentNode.SelectSingleNode(allXPath + "/a[1]").Attributes["href"].Value;
richTextBox3.AppendText("地址:" + adr + "\r\n"); //百度快照日期
string pDateXPath = navNode.XPath + "/tr[1]/td[1]/font[1]/span[1]";
string pDate = hd.DocumentNode.SelectSingleNode(pDateXPath).InnerText;
if (pDate != string.Empty)
{
richTextBox3.AppendText("百度快照:" + pDate + "\r\n");
string dataP = Regex.Match(pDate, @"\d{4}([-/])\d{1,2}\1\d{1,2}").Value;
richTextBox3.AppendText("快照日期:" + dataP + "\r\n\r\n");
}
else
richTextBox3.AppendText("\r\n\r\n");
}
catch (Exception)
{
richTextBox3.AppendText("\r\n");
}
}
}