I used the HtmlAgilityPack
for work with html pages.
Previously I did this:
HtmlWeb web = new HtmlWeb();
HtmlDocument document = web.Load(url);
var nodes = document.DocumentNode.SelectNodes("necessary node");
but now i need to use the HtmlAgilityPack.NETCore where HtmlWeb
is absent.
What should i use instead HtmlWeb
to have the same result?
You can use HttpClient to get the content of the page.
I had the same problem in Visual Studio code with netcoreapp1.0. Ended up using HtmlAgilityPack version 1.5.0-beta5 instead.
Remember to add:
I did it like this:
Use the
HttpClient
as a new way to interact with remote resources via http.As for your solution, you probably need to use the
async
methods here for non-blocking your thread, instead of.Result
usage. Also note thatHttpClient
was meant to be used from different threads starting from .Net 4.5, so you should not recreate it each time:Great article about async/await: Async/Await - Best Practices in Asynchronous Programming by @StephenCleary | March 2013
I wrote this and it's working. Is this a good way to solve my problem?