use*_*981 10 c# asp.net ironpython screen-scraping beautifulsoup
有没有人将BeautifulSoup与ASP.NET/C#集成(可能使用IronPython或其他方式)?是否有一个BeautifulSoup替代品或一个与ASP.NET/C#很好地工作的端口
计划使用该库的目的是从任何随机URL中提取可读文本.
谢谢
Col*_*ard 14
Html Agility Pack是一个类似的项目,但对于C#和.NET
编辑:
要提取所有可读文本:
document.DocumentNode.InnerText
Run Code Online (Sandbox Code Playgroud)
请注意,这将返回<script>
标签的文本内容.
要解决此问题,您可以删除所有<script>
标记,如下所示:
foreach(var script in doc.DocumentNode.Descendants("script").ToArray())
script.Remove();
foreach(var style in doc.DocumentNode.Descendants("style").ToArray())
style.Remove();
Run Code Online (Sandbox Code Playgroud)
(信用:SLaks)