Monday 15 April 2013

c# - retrieve data from other sites using XPath -



c# - retrieve data from other sites using XPath -

i trying retrieve info other sites using html agilitypack help of xpath. have added info 1 site when alter url , xpath retrieve info site, not work.

here working code:

string url = "http://www.uok.edu.pk/faculties/computerscience/bs.php"; htmlagilitypack.htmlweb web = new htmlweb(); htmlagilitypack.htmldocument doc = web.load(url); var headers = doc.documentnode.selectnodes( "//*[@id=\"courses_sec\"]/div[2] /div[2]/div[2]/table[2]/tbody/tr[1]/td");

but alter xpath , url, variable headers null. code not working:

string url = "http://music.dodear.com/index.php"; htmlagilitypack.htmlweb web = new htmlweb(); htmlagilitypack.htmldocument doc = web.load(url); var headers = doc.documentnode.selectnodes( "//*[@id=\"content\"]/div[2]/table/tbody/tr[2]/td/table/tbody/tr/td/ table[1]/tbody/tr/td");

either xpath wrong, or html has sort of bad format (tags don't close, etc) may necessitate complex xpath access. why don't break downwards xpath piece-by-piece? example, 1 time web.load(url) load htmldocument, can watch on

doc.documentnode.selectsinglenode("//*[@id=\"content\"]").innerhtml;

then

doc.documentnode.selectsinglenode("//*[@id=\"content\"]/div[2]").innerhtml;

then

doc.documentnode.selectsinglenode("//[@id=\"content\"]/div[2]/table").innerhtml;

etc.

so can figure out problem is

c# .net xpath

No comments:

Post a Comment