visual studio - Using C# HTML agility pack to scrape the Image Source out of a particular table in a html page -


i'm trying extract image sources out of 1 table in page, code extracting image sources of whole page, not 1 table. on helping me able extract image source out of first table in html page appreciated.

 var tables= html.documentnode.selectnodes("//table[1]").tolist();   foreach (var table in tables)  {      if (html.documentnode != null)      {          var images = html.documentnode.selectnodes("//img/@src");           if (images.any())          {              bodylist.addrange(images.select(t => t.outerhtml + (i + 1).tostring()));          }      }                    } 

select table nodes first instead of image ones , select images nodes

    var tables = html.documentnode.selectnodes("//table").tolist();     list<string> bodylist = new list<string>();     foreach (var table in tables)     {         if (html.documentnode != null)         {             var images = table.selectnodes("//img/@src");              if (images.any())             {                 bodylist.addrange(images.select(t => t.outerhtml + (i + 1).tostring());             }         }                       } 

this extract images out of tables in html, extract first one

list<string> bodylist = new list<string>(); var table = html.documentnode.selectnodes("//table").firstordefault(); if (table != null) {     bodylist.addrange(table.selectnodes("//img/@src").select(t => t.outerhtml + (i + 1).tostring()); } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -