AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.
https://anglesharp.github.io
MIT License
72 stars 34 forks source link

How to load HTML document from local filesystem? #115

Closed IanKemp closed 2 years ago

IanKemp commented 2 years ago

Using AngleSharp 0.17.1 in a .NET 6 console app.

test.html lives in the same directory as my Program.cs and has "Copy to Output Directory" set to "Copy always". I've also verified that it appears in the bin\Debug\net6.0 directory alongside the compiled EXE. And if I copy the contents of htmlFile and paste it into a browser URL bar and press Enter, the page does indeed appear.

Thus I would expect the following code to load my HTML file, yet in practice document is always NULL. Where am I going wrong?

var config = Configuration.Default
    .WithDefaultLoader(new LoaderOptions { IsResourceLoadingEnabled = true });

var context = BrowsingContext.New(config);
var htmlFile = $"file:{Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "test.html")}";

var document = await context.OpenAsync(htmlFile);
IanKemp commented 2 years ago

Whoops, posted in wrong repo!