开发者

Get google Search position

i want to find on which page my link is located for given seatch word with out navigating to each page. Is it possible i am using winforms c#

lets say i have to find link facebook.com for search开发者_开发百科 word social networking and see on which google page is this link present


Dude, you should not parse HTML with regexp. I'm not explaining why here, there's much information on why around here. A solution to get all results using HtmlAgilityPack and XPATH:

public IEnumerable<string> GetResults(string html) {
    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(html);

    foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//span[@class='tl']/h3/a"))
    {
        var value = link["href"].Value;
        yield return value;
     }
 }

This will fetch all links matching our XPATH //span[@class='tl']/h3/a (SERP items, no PPC etc.) and return the href attribute.

A easier way to get your html is using WebClient, like:

using(var wc = new WebClient())
{
   return wc.DownloadString("http://www.google.com/search?q=" + HttpUtility.HtmlEncode(searchTerm));
}

You obviously need to do the downloading and comparison yourself, but this should get you going.


try using http://code.google.com/apis/customsearch/v1/overview.html - although it's limited to 100 queries per day

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜