Tag in einem externen HTML mit HTML Agility Pack? c# html html-agility-pack xpath
Ich versuche, Text von einer externen Website zu erhalten. Der Text, den ich zu erhalten versuche, ist in einem Absatz-Tag verschachtelt. Das div hat einen Klassenwert
HTML-Codeschnipsel:
<div class="discription"><p>this is the text I want to grab</p></div>
Aktueller c # -Code:
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;
}
}
Was ich nicht verstehe, ist die Syntax des xpath //div[@class='discription']
Ich weiß, dass es falsch ist, was sollte der xpath sein?
benutze //div[@class='discription']/p
.
Nervenzusammenbruch:
//div - All div elements
[@class='discription'] - With a class attribute whose value is discription
/p - Select the child p elements