Reputation: 7419
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
Upvotes: 0
Views: 1158
Reputation: 58962
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.
Upvotes: 2
Reputation: 1979
try using http://code.google.com/apis/customsearch/v1/overview.html - although it's limited to 100 queries per day
Upvotes: 0