Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Agility Pack 2

I am tring to scrap This Website . The below Xpath expression working fine with FirePath firebug extension

html/body/table/tbody/tr[3]/td

But using same xpath expression the below code gives me null :

 HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
 HtmlWeb web = new HtmlWeb();

 doc = web.Load("http://www.edb.gov.hk/templates/sch_list_print.asp?district=cw");
 var collection= doc.DocumentNode.SelectNodes("html/body/table/tbody/tr[3]/td");

Can anyone help me on this. Thanks.

like image 933
Burfi Avatar asked Apr 21 '26 21:04

Burfi


1 Answers

this works, looking at the source of the page you are trying to scrape there is no tbody inside of table.

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
HtmlWeb web = new HtmlWeb();

doc = web.Load("http://www.edb.gov.hk/templates/sch_list_print.asp?district=cw");
var collection= doc.DocumentNode.SelectNodes("html/body/table/tr[3]/td");

change your xpath to

html/body/table/tr[3]/td
like image 62
Christian Westman Avatar answered Apr 23 '26 10:04

Christian Westman