Click here to Skip to main content
16,011,619 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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");
Posted
Updated 21-May-19 4:04am

Quote:
C#
var node = doc.DocumentNode.SelectSingleNode("\\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:
C#
var node = doc.DocumentNode.SelectSingleNode("//div[@class]");
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900