div에서 htmlagilitypack .net html-agility-pack parsing winforms
이 같은 단락 태그를 포함하는 div 있습니다.
<div class="div_5">
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Third Paragraph</p>
<p>Fourth Paragraph</p>
</div>
<div class="div_5">
<p>First Paragraph</p>
<p>Second Paragraph</p>
<p>Third Paragraph</p>
<p>Fourth Paragraph</p>
</div>
나는 htmlagiitypack을 사용하여 모든 paragrap 텍스트의 텍스트를 가져올 필요가있다.
Dim oPB As HAP.HtmlNodeCollection = doc.DocumentNode.SelectNodes("//div[@class='post-bodycopy clearfix']/child::text()/"]
For Each item As HAP.HtmlNode In oPB
debug.print(item.InnerText)
Next
각 div 문자열에 대해 기대되는 출력은 다음과 같습니다.
First Paragraph
Second Paragraph
Third Paragraph
Fourth Paragraph
하지만 텍스트 일부 html을 받고, 누군가가 나를 문제를 해결할 수 있습니다.
실제로 단락의 내부 텍스트를 선택해야합니다. 당신의 xpath는 완전히 다른 것을 얻습니다.
Dim query = doc.DocumentNode.SelectNodes("//div[@class='div_5']/p/text()")