AngleSharp / AngleSharp.Css

:angel: Library to enable support for cascading stylesheets in AngleSharp.

Home Page:https://anglesharp.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to load HTML document from local filesystem?

IanKemp opened this issue · comments

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);

Whoops, posted in wrong repo!