如何使用 CsQuery 删除 html 内容中的所有脚本标签
how to remove all script tags in a html content with CsQuery
我正在使用 CsQuery 库进行抓取。代码是这样的
var dom = CQ.CreateDocument(htmlContent);
resultText= dom[cssSelector].Text();
我不想要 resultText
中的脚本标签,例如这部分 <script> somethings </script>
我试过这个dom[cssSelector].Not("script").Text();
。但是没有用。
如何删除所有脚本值?
库三年多没更新了,可能已经失效了。
查看给定的文档,您可以尝试使用:
CQ script = dom["script"];
script.remove();
这将删除所有脚本标签
已解决。此代码删除所有脚本。
dom = dom["body script"].Remove();
我正在使用 CsQuery 库进行抓取。代码是这样的
var dom = CQ.CreateDocument(htmlContent);
resultText= dom[cssSelector].Text();
我不想要 resultText
中的脚本标签,例如这部分 <script> somethings </script>
我试过这个dom[cssSelector].Not("script").Text();
。但是没有用。
如何删除所有脚本值?
库三年多没更新了,可能已经失效了。
查看给定的文档,您可以尝试使用:
CQ script = dom["script"];
script.remove();
这将删除所有脚本标签
已解决。此代码删除所有脚本。
dom = dom["body script"].Remove();