大家好,怎么用C#抓取谷歌的搜索结果,哪个高手有写过呢。谢谢

解决方案 »

  1.   

    http://blog.csdn.net/lsgy2008/article/details/6308544
      

  2.   

    做过获取百度的 用的HtmlAgilityPack
    给你找下代码
      

  3.   

          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");
                        }
                    }
                }
      

  4.   

    我现在想抓取Google英国的,可是获取不到html代码,都被屏蔽掉了,不知道该如何是好呢