質問

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?

役に立ちましたか?

解決 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.

他のヒント

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 );            
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top