如何用C#中的htmlagilitypack解析这个 [英] How to parse this with htmlagilitypack in C#

查看:106
本文介绍了如何用C#中的htmlagilitypack解析这个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论我做什么,我都无法进入这个班级与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.'







这是我现在拥有的价格





https://hastebin.com/igavulogax.js



我的尝试:






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");

推荐答案

Quote:

var node = doc.DocumentNode.SelectSingleNode("\\div class");

SelectSingleNode方法 [ ^ ]需要一个XPath表达式。字符串 \ diviv 不是XPath表达式。



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]");


问题在于HTML。显示你的一点点代码没什么区别。



即使它是HtmlAgilityPack中的bug,没有人可以帮助你。
The problem is with the HTML. Showing your little bit of code make no difference.

Even if it was a "bug" in the HtmlAgilityPack, no one can help you.


这篇关于如何用C#中的htmlagilitypack解析这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆