I got this code that brings me the search results from Google as an HTML string:
WebClient webClient = new WebClient();
string htmlString = webClient.DownloadString("http://www.google.com/search?q=" + searchQuery);
Any idea how to extract only the links from it ? I guess I do a string search, but it doesn't look so elegant...
I found this code
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(htmlString);
var selectNodes = htmlDoc.DocumentNode.SelectNodes("//li[@class='g']");
foreach (var node in selectNodes)
{
//node.InnerText will give you the text content of the li tags ...
}
But I'm getting an exception that var selectNodes = htmlDoc.DocumentNode.SelectNodes("//li[@class='g']");
is null...