【发布时间】:2013-10-07 09:06:32
【问题描述】:
我有一个 C# 代码,我想在其中提取以下值(下面的 HTML 代码中的文本“我想要这个文本”)。我已重新格式化 HTML 代码以使其易于阅读。
<div class="paste-copy-url" style="margin:0 0 0 0;">
<h4>My Stats:</h4>
<div class="line">
<div class="wrap-input">
<input onclick="this.select();" value="I want this text" readonly="readonly">
</div>
</div>
<h4>Website Link:</h4>
<div class="line">
<div class="wrap-input"><input onclick="this.select();" value="Some value" readonly="readonly">
</div>
</div>
</div>
我试过的代码(它给了我文字:“网站链接:”):
var myvaluetoextract = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='paste-copy-url']");
我做错了什么?我可以使用这种方法来获取该元素吗(页面中只有 div 类的 1 个实例)?
【问题讨论】:
-
你的意思是
myvaluetoextract是null...上面的xpath是正确的,应该可以工作.. -
它给了我文字:“网站链接:”(标题而不是我想要的值)
-
@touyets 你说的是
returns a null value,现在说It is giving me the text : "Website Link:"。哪一个是正确的? -
我编辑了我的帖子。正确的是我更正页面网址后的结果:它给了我文字:“网站链接:”
标签: c# html css html-agility-pack