문제

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