2011-11-16 158 views
2

我想获得谷歌搜索结果使用HTML敏捷包,但我没有得到正确的页面。我得到的网页是谷歌的主页,获取谷歌搜索结果在c#

这是的C#的web浏览器给我的链接: https://www.google.com/#sclient=psy-ab&hl=en&site=&source=hp&q=hello+world&pbx=1&oq=hello+world&aq=f&aqi=&aql=&gs_sm=e&gs_upl=14782l16242l0l16965l11l7l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=5586f0ad4776d5b3&biw=268&bih=250

(如果你尝试将其粘贴到一个正常的浏览器,它会变成下面的网址)

这是,如果我用一个普通的浏览器: https://www.google.com/search?sclient=psy-ab&hl=en&site=&source=hp&q=hello+world&pbx=1&oq=hello+world&aq=f&aqi=&aql=&gs_sm=e&gs_upl=14782l16242l0l16965l11l7l0l0l0l0l0l0ll0l0&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=268&bih=250&cad=h

private void GotoGoogleButton(object sender, EventArgs e) 
{ 
    webBrowser1.Navigate(new Uri("https://www.google.com")); 
} 

private void getResultsButton(object sender, EventArgs e) 
{ 
    url = webBrowser1.Url.ToString(); 
    start_parsing(url); 
} 

public void start_parsing(string URL_) 
{ 
    //This function is used to Parse Html source using Html Agility Pack into nodes, and take the important ones (mainly : a,form,iframe) 

    HtmlAgilityPack.HtmlDocument document = webGet.Load(URL_); 
    var metaTags = document.DocumentNode.SelectNodes("//a"); 

    // ... 

    // Continue with parsing... 
} 

我如何获得的搜索结果,而不是主页?

+1

您必须格式化你的代码(在您的文章,并在你的编辑)。否则,人们无法阅读。 –

回答

2

我想你会得到更好的服务寻找到Google's RESTful API for search

看样子你可以得到包含搜索结果的Atom提要。

+0

我做了,并正在努力,但没有其他方式?! – dimazaid

+1

是的,你可以一起破解一个屏幕刮板,但最终会导致一些麻烦。使用api是可靠地解决您面临的问题的最佳方法 – Jason

2

只需将#替换为search?即可。但为什么你不能使用google search api这个

+0

我替换它们#并搜索?但他们不是唯一的区别2链接 – dimazaid

+0

@Chamika Sandamal Works很棒,谢谢 –