2011-11-16 154 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很棒,謝謝 –