我有这个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")有谁有什么想法吗?
谢谢。
发布于 2011-10-15 07:09:51
尝试此操作(提前警告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希望这能有所帮助。
https://stackoverflow.com/questions/7774260
复制相似问题