Attempting to parse HTML using AngleSharp and running into issues with https://opensource.org/licenses/MS-PL
The following code is returning '0' while running in Linqpad
var url = @"https://opensource.org/licenses/MS-PL";
var doc = await AngleSharp.BrowsingContext.New().OpenAsync(url);
doc.Body.ChildElementCount.Dump();
I would expect the full HTML to come back as part of the body. Any ideas?
When creating a new BrowsingContext without supplying an IConfiguration, it uses a default config that does not support document loading. You need to create a config that does and pass it to the BrowsingContext.New.
var config = Configuration.Default.WithDefaultLoader();
var doc = await AngleSharp.BrowsingContext.New(config).OpenAsync(url);
Most likely, the accepted answer covers 95%+ of the devs that run into this issue. However, today I ran into this issue for a different reason.
When using AngleSharp's IResponse, you cannot open the same response twice with browsingContext.OpenAsync(response). After reading the response successfully the first time, you'll get an empty document each time thereafter. The solution here is to rewrite your code so you don't open the same response twice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With