用于本地HTML文件的HTML解析器 [英] HTML Parser for local HTML files

查看:34
本文介绍了用于本地HTML文件的HTML解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够解析HTML模板文件(目的是将SVG元素注入html文件,然后通过wkhtmltopdf将其转换为pdf).

I need to be able to parse an HTML template file (with the intention of injecting an SVG element into a html file, then converting it to pdf via wkhtmltopdf).

我了解HTML Agility Pack,但似乎无法解析本地文件(尝试使用file://URI导致其引发异常).

I know about the HTML Agility Pack, but it seems incapable of parsing local files (attempts to use file:// URIs have caused it to throw exceptions).

那么,谁能为本地HTML文件推荐C#HTML解析器?

So, can anyone recommend a C# HTML parser for local HTML files?

推荐答案

HTML Agility Pack适用于本地文件,请查看此文档中的rel ="nofollow noreferrer">示例.

HTML Agility Pack is fine for local files, check out this example from the docs.

或者,使用文件将文件中的内容加载到字符串中.ReadAllText ,然后将其传递到 HtmlDocument.LoadHtml(string html).

Alternatively, load the content from the file into a string using something like File.ReadAllText then pass it into HtmlDocument.LoadHtml(string html).

这篇关于用于本地HTML文件的HTML解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆