Frage

I'm trying to use HtmlAgilityPack, namely a HtmlWeb.LoadAsync method which is commonly mentioned in internet. But it cannot be resolved by Visual Studio. HtmlWeb class is resolved, but LoadAsync method is not. My project is WPF 4.5 Windows desktop application. I have loaded HtmlAgilityPack Nuget package, HtmlAgilityPack library is in references (version 1.4.6.0) and using HtmlAgilityPack; is in code too, but it still cannot resolve. What could be the problem?

War es hilfreich?

Lösung 2

It seems that LoadAsync() only available on HtmlAgilityPack version for platforms where synchronous download is not supported by default eg. HAP for Metro apps, Silverlight, Windows Phone, etc.

For WPF application, use synchronous Load() method. And if you need it to load HtmlDocument asynchronously, you could manually run Load() method in different, non-UI thread.

Andere Tipps

I would download the HTML text asynchronously and then process it. Something like this:

var htmlDoc = await client.DownloadStringTaskAsync(url)

HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
htmlDocument.LoadHtml(htmlDoc );            
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top