我有一个小问题。我正在尝试获取 html 元素之外的文本。 输入示例:
I want this text I want this text I want this text <I don't want this text/>
I want this text I wan this text <I don't>want this</text>
有人知道正则表达式怎么可能吗?我以为我可以通过删除元素文本来实现。那么,有人知道这个问题的另一种解决方案吗?请帮助我。
请您参考如下方法:
而不是正则表达式,即 not suitable for parsing HTML in general (特别是格式错误的 HTML),使用像 HTML Agility Pack 这样的 HTML 解析器.
What is exactly the Html Agility Pack (HAP)?
This is an agile HTML parser that builds a read/write DOM and supports plain XPATH or XSLT (you actually don't HAVE to understand XPATH nor XSLT to use it, don't worry...). It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System.Xml, but for HTML documents (or streams).
