问题描述
无论我做什么,我都无法进入这个班级与htmlaglility包一起工作:(我试图进入div并解析出高宽度的名称和网址,但是当我使用aglilty pack时我一直收到无效通话
no matter what i do i cant get into this class to work with htmlaglility pack :( i trying to get into the div and parse out hight width name and url but i keep getting invalid call when i use aglilty pack
System.Xml.XPath.XPathException: ''\div class' has an invalid token.'
这是我现在拥有的价格
我的尝试:
this is what i currently have
https://hastebin.com/igavulogax.js
What I have tried:
var url = "https://sketchfab.com/3d-models/steyr-aug-a3-4cea993b9f0d47c6b1beed7877b17447";
using (HttpClient client = new HttpClient())
{
using (HttpResponseMessage response = client.GetAsync(url).Result)
{
using (HttpContent content = response.Content)
{
string result = content.ReadAsStringAsync().Result;
System.IO.File.WriteAllText(Application.StartupPath + "rip.html", result);
}
}
}
var path = Application.StartupPath + "rip.html";
var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(path);
var node = doc.DocumentNode.SelectSingleNode("\\div class");
推荐答案
var node = doc.DocumentNode.SelectSingleNode("\\div class");
[]需要一个XPath表达式。字符串 \ diviv
不是XPath表达式。
[]
如果你想选择所有< div>
元素有一个 class
属性,使用:
The SelectSingleNode method[^] expects an XPath expression. The string \div class
is not an XPath expression.
XPath Tutorial[^]
If you want to select all <div>
elements which have a class
attribute, use:
var node = doc.DocumentNode.SelectSingleNode("//div[@class]");
这篇关于如何用C#中的htmlagilitypack解析这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!