简体   繁体   English

如何使用CsQuery删除html内容中的所有脚本标签

[英]how to remove all script tags in a html content with CsQuery

i am using CsQuery library for crawling. 我正在使用CsQuery库进行爬网。 Code is like this. 代码是这样的。

 var dom = CQ.CreateDocument(htmlContent);
resultText= dom[cssSelector].Text();

I don't want script tags in resultText for example this part <script> somethings </script> 我不需要resultText脚本标签,例如这部分<script> somethings </script>

I tried this dom[cssSelector].Not("script").Text(); 我尝试了这个dom[cssSelector].Not("script").Text(); . But is not working. 但是没有用。

How can i delete all script values? 如何删除所有脚本值?

The library hasn't been updated in over three years, so it is possible that it no longer works. 该库三年未更新,因此有可能不再起作用。

Looking at the given documentation, you can try using: 查看给定的文档,您可以尝试使用:

CQ script = dom["script"];
script.remove();

This will remove all script tags 这将删除所有脚本标签

Solved. 解决了。 This code removes all scripts. 此代码删除所有脚本。

dom = dom["body script"].Remove();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM