사이트 중 하나에 대한 크롤러를 작성 중이며이 문제가 발생했습니다. 이 HTML에서 XPath로 어떻게 얻을 수 있습니까?
...<div class="Price">
<span style="font-size: 14px; text-decoration: line-through; color: #444;">195.90 USD</span>
<br />
131.90 USD
</div>
나는 XPath를 사용하는 경우에만 131.90 USD 얻을 필요가있다. 이 시도
..."//div[@class='Price']"
그러나 다른 결과를 반환합니다.
어떻게하면됩니까?
편집
난 당신이 시도는 XPath가있다
public static class Helper {
public static String GetInnerText(HtmlDocument doc, String xpath) {
var nodes = doc.DocumentNode.SelectNodes(xpath);
if (nodes != null && nodes.Count > 0) {
var node = nodes[0];
return node.InnerText.TrimHtml();
}
return String.Empty;
}
public static String GetInnerText(HtmlNode inputNode, String xpath) {
var nodes = inputNode.SelectNodes(xpath);
if (nodes != null && nodes.Count > 0) {
var node = nodes[0];
var comments = node.ChildNodes.OfType<HtmlCommentNode>().ToList();
foreach (var comment in comments)
comment.ParentNode.RemoveChild(comment);
return node.InnerText.TrimHtml();
}
return String.Empty;
}
public static String GetInnerHtml(HtmlDocument doc, String xpath) {
var nodes = doc.DocumentNode.SelectNodes(xpath);
if (nodes != null && nodes.Count > 0) {
var node = nodes[0];
return node.InnerHtml.TrimHtml();
}
return String.Empty;
}
public static string GetInnerHtml(HtmlNode inputNode, string xpath) {
var nodes = inputNode.SelectNodes(xpath);
if (nodes != null && nodes.Count > 0) {
var node = nodes[0];
return node.InnerHtml.TrimHtml();
}
return string.Empty;
}
}
장소? HtmlAgilityPack? LINQ2XML? – Arran
HtmlAgilityPack. – Zafar
현재 어떤 코드를 사용하고 있습니까? – Arran