我正在尝试从外部网站获取一些文本。我想要获得的文本嵌套在段落标记中。 div具有类值
html代码段:
<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应该是什么错误?
答案 0 :(得分:0)
使用//div[@class='discription']/p
。
故障:
//div - All div elements
[@class='discription'] - With a class attribute whose value is discription
/p - Select the child p elements