开发者

get number of pages in search results

I want to get number of pages at the bottom of any search page say google or bing then i have to store the links of those pages for further navigation.

How can this be Done?

What approach should be used HTMLAGILITYPACK or HTTPWEBREQUEST or any other.It would be great if somebody demonstrate how to get tags with specific attributes i.e class name or ID

Google has nested like href has Span inside so we can have url from href but how to get span

get number of pages in search results

text so that i can save it with 开发者_JS百科name as page 1 url http:/blabla.com


Using the HTML Agility Pack:

var doc = new HtmlWeb().Load(url);
var elem = doc.GetElementById("someID");
var classedLinks = doc.DocumentNode.Descendants("img")
    .Where(e => e.GetAttributeValue("class", "").Contains("SomeClass"));


Combined some code from SLaks and generated following code that gets navigation links at bottom of google

 HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
 HtmlAgilityPack.HtmlDocument doc = web.Load("http://www.google.com.pk/search?rlz=1C1SKPL_enPK414PK414&sourceid=chrome&ie=UTF-8&q=asd");

 foreach (HtmlNode table in doc.DocumentNode.Descendants("table").Where(e => e.GetAttributeValue("id", "").Contains("nav")))
 {
     foreach (HtmlNode row in table.SelectNodes("tr"))
     {
      foreach (HtmlNode cell in row.SelectNodes("th|td"))
      {
          MessageBox.Show("cell: " + cell.InnerHtml);
      }
 }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜