외부 민첩성 팩을 사용하여 외부 HTML 태그? c# html html-agility-pack xpath
외부 사이트에서 일부 텍스트를 가져 오려고합니다. 내가 얻으려고하는 텍스트는 단락 태그에 중첩되어 있습니다. div has에는 클래스 값이 있습니다.
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가 무엇이되어야하는지 잘못 알고 있습니까?
//div[@class='discription']/p
.
고장:
//div - All div elements
[@class='discription'] - With a class attribute whose value is discription
/p - Select the child p elements