1

我有这个html。我正在尝试获取其中没有任何标签的 InnerText,

<h1>my h1 content</h1>
<div class="thisclass">
<p> some text</p>
<p> some text</p>
    <div style="some_style">
    some text
        <script type="text/javascript">
        <!-- some script -->
        </script>
    <script type='text/javascript' src='some_script.js'></script>
    </div>
<p> some text<em>some text</em>some text.<em> <br /><br /></em><strong><em>some text</em></strong></p>
    <p> </p>
   </div>

我想要做的是获取用户从 thisclass 类中看到的文本。我想剥离任何脚本标签和所有标签,只得到纯文本。

这就是正在使用的:

 Dim Tags As HtmlNodeCollection = root.SelectNodes("//div[@class='thisclass'] | //h1")

有没有人有任何想法?

谢谢。

4

1 回答 1

0

试试这个(警告 c# 代码提前):

foreach(var script in root.SelectNodes("//script"))
{
    script.ParentNode.RemoveChild(script);
}

Console.WriteLine(root.InnerText);

这给了我以下输出:

my h1 content some text some textsome text    some textsome textsome text. some text

希望这可以帮助。

于 2011-10-14T23:09:51.343 回答