WebBrowser - HtmlDocument

Topics: Developer Forum, Project Management Forum, User Forum
Dec 25, 2009 at 4:51 PM
Edited Dec 25, 2009 at 4:53 PM

Does anyone know how to solve this problem below?

 

HtmlAgilityPack.HtmlDocument doc;
doc = webBrowser1.Document;

It gives me this error:

Cannot implicitly convert type "System.Windows.Forms.HtmlDocument" to 'HtmlAgilityPack.HtmlDocument'

I want to parse html from a webbrowser.

Thanks.

Dec 25, 2009 at 5:59 PM

the webbrowser controls Document property is not an HtmlAgilityPack HtmlDocument object, it is an HtmlDocument object that belongs to System.Window.Forms . Other than their name, they have no relation to each other.

 

Coordinator
Dec 27, 2009 at 11:26 AM

You should try this instead

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(webBrowser1.DocumentStream);

Note: this could be added as a cast operator to the Html Agility Pack HtmlDocument class so your original code would compile as is...