BeautifulSoup and ASP.NET/C#

回眸只為那壹抹淺笑 提交于 2019-12-03 12:29:40

问题


Has anyone integrated BeautifulSoup with ASP.NET/C# (possibly using IronPython or otherwise)? Is there a BeautifulSoup alternative or a port that works nicely with ASP.NET/C#

The intent of planning to use the library is to extract readable text from any random URL.

Thanks


回答1:


Html Agility Pack is a similar project, but for C# and .NET


EDIT:

To extract all readable text:

document.DocumentNode.InnerText

Note that this will return the text content of <script> tags.

To fix that, you can remove all of the <script> tags, like this:

foreach(var script in doc.DocumentNode.Descendants("script").ToArray())
    script.Remove();
foreach(var style in doc.DocumentNode.Descendants("style").ToArray())
    style.Remove();

(Credit: SLaks)




回答2:


You could try this although it currently has a few bugs:

http://nsoup.codeplex.com/




回答3:


I know this is quite old, but I decided to post this for future reference. I came across this searching for a similar solution.

I found a library built on top of Html Agility Pack called scrapysharp

I've used it in quite similar manner as I would BeautifulSoup https://bitbucket.org/rflechner/scrapysharp/wiki/Home



来源:https://stackoverflow.com/questions/3357170/beautifulsoup-and-asp-net-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!