![](/img/trans.png)
[英]How to extract different divs between two anchor tags in htmlagility?
[英]How to get text between two div tags with some class attribute with HTMLagility
我想從HTML文件的兩個html div中獲取一些文本。 經過一些搜索后,我決定使用HTMLAgility Pack來執行此操作。 我寫了這段代碼:
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(result);
HtmlNode node = doc.DocumentNode.SelectSingleNode("//*div[@class='item']");
string value = node.InnerText;
“結果”是我在文件中的內容。 但是我遇到了一個例外:“表達式必須計算為一個節點集”
這是mt文件的一些內容:
<div class="Clear" style="height:15px;"></div>
<div class='Container Select' id="Container_1">
<div class='Item'><div class='Part Lable'>موضوع : </div><div class='Part ...
嘗試之一
"//*/div[@class='item']"
或簡單地
"//div[@class='item']"
您是否嘗試過使用XPath例如,如果我想查找示例中是否選擇了節點,我將執行以下操作
string xpath = null;
XmlNode configNode = configDom.DocumentElement;
// collect selected nodes in node list
XmlNodeList nodeList =
configNode.SelectNodes(@"//*[@status='checked']");
在您的情況下,您將執行以下操作
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(result);
HtmlNode node = doc.DocumentNode.SelectSingleNode("//*/div[@class='item']");
string value = node.InnerText;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.