【发布时间】:2012-04-27 06:46:48
【问题描述】:
我正在尝试从外部站点获取一些文本。我要获取的文本嵌套在段落标签中。 div 有一个类值
html代码sn-p:
<div class="discription"><p>this is the text I want to grab</p></div>
当前 c# 代码:
public String getDiscription(string url)
{
var web = new HtmlWeb();
var doc = web.Load(url);
var nodes = doc.DocumentNode.SelectNodes("//div[@class='discription']");
if (nodes != null)
{
foreach (var node in nodes)
{
string Description = node.InnerHtml;
return Description;
}
} else
{
string error = "could not find text";
return error;
}
}
我不明白的是 xpath //div[@class='discription'] 的语法我知道 xpath 应该是什么是错误的?
【问题讨论】:
标签: c# html xpath html-agility-pack