How can I extract an image from a website using HtmlAgilityPack and XPath? (C#)

  • Thread starter Thread starter Ethan Ollins
  • Start date Start date
E

Ethan Ollins

Guest
Hello, everyone. I have been making a Comic Viewer in C#, and Im stumped on how to actually load the comics. I installed HtmlAgilityPack and I have the XPath for the image I need, so I did some research and added the following code:


string url = "http://www.gocomics.com/bignate/2015/04/10";
HtmlWeb web = new HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load(url);

var imgsrc = doc.DocumentNode.SelectSingleNode("//*[@id=\"zoom_content\"]/img").Attributes["src"].Value;
pictureBox1.ImageLocation = imgsrc;


However, it throws an unhandled exception and the imgsrc ends up null. What am I doing wrong?

Continue reading...
 
Back
Top