XPath to get values using AgilityPack from HTML page -


i need numeric values web page 2 variables.

a snippet page below

<b>downloads (current version):</b> 123                  <br /> <b>downloads (total):</b> 253</td> <br /> 

the "downloads (current version):" , "downloads (total):" unique strings in page.

i need "123" , "253" variables

edit: har07 ended with

var downloadscurrentversion = htmldoc.documentnode.selectsinglenode(@"//b[.='downloads (current version):']/following-sibling::text()[1]"); var downloadsallversions = htmldoc.documentnode.selectsinglenode(@"//b[.='downloads (total):']/following-sibling::text()[1]");  console.writeline("total: " + downloadsallversions.innertext.trim()); console.writeline("current: " + downloadscurrentversion.innertext.trim()); 

check example :

var html = @"<div> <b>downloads (current version):</b> 123                  <br /> <b>downloads (total):</b> 253</td> <br /> </div>"; var htmldoc = new htmldocument(); htmldoc.loadhtml(html); var result = htmldoc.documentnode.selectnodes("/div/text()[normalize-space(.)]"); foreach (var r in result) {     console.writeline(r.innertext.trim()); } 

this part of xpath above example :

/div/text() 

means, select text nodes direct child of <div> element. , last part :

[normalize-space(.)] 

filters out empty text nodes.

update :

responding comment, can try way instead :

var result =          htmldoc.documentnode                .selectnodes(@"/div/b[.='downloads (current version):'                                          or                                       .='downloads (total):']/following-sibling::text()[1]"); 

above xpath selects text node directly after specific <b> elements.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -