i trying use htmlagilitypack obtain image src="" value group of images on webpage , add them list of strings.
i have tried following don't img tags.
dim htmldoc new htmldocument() htmldoc.loadhtml(getpage(new uri(product.link))) each imageshow htmlnode in htmldoc.getelementbyid("slideshow").childnodes each image in imageshow.elements("img") console.writeline(image.attributes("src").value) product.otherimages.add(image.attributes("src").value) next next the webpage follows.
<html xmlns="http://www.w3.org/1999/xhtml"> <head> ... </head> <body> .... <div id="slideshow" class="slideshow"> <div class="slides"> <div class="slide"> <a href="http://mywebsite.com/images/some1.jpg"> <img src="http://mywebsite.com/images/some1.jpg" /> </a> <div> <div class="slide"> <a href="http://mywebsite.com/images/some2.jpg"> <img src="http://mywebsite.com/images/some2.jpg" /> </a> <div> ... </div> <div> .... </body> </html> i expecting image.attributes("src").value "http://mywebsite.com/images/some1.jpg"
i didn't know xpath component , able select nodes using expressions below.
dim htmldoc new htmldocument() htmldoc.loadhtml(getpage(new uri(product.link))) each slidesnode in htmldoc.documentnode.selectnodes("//div[@id='slideshow']//div[@class='slides']") each slide in slidesnode.selectnodes(".//div[@class='slide']") console.writeline(slide.selectsinglenode(".//a//img").attributes("src").value) next next i wasn't sure if there quicker or better way access each image in slide node, seems work now.
Comments
Post a Comment