开发者

C#: Selecting the Text of a Node using HTML Agility Pack and XPath

开发者 https://www.devze.com 2023-04-01 13:31 出处:网络
having a problem with selecting the text contain within a particular node on HTML Page. I haven\'t used XPath before but using the HAP Explorer this was the path given for the text I wanted

having a problem with selecting the text contain within a particular node on HTML Page. I haven't used XPath before but using the HAP Explorer this was the path given for the text I wanted

        string xpath = "/html[1]/body[1]/div[2]/div[4]/div[1]/div[3]/div[4]/div[1]/div[6]/div[1]/div[4]/div[5]/table[1]/tr[1]/td[2]/span[1]";
        //Using WatiN for Browser Control
        IE ie = new IE(url);
        ie.W开发者_如何学CaitForComplete();
        var html = new HtmlDocument();
        html.LoadHtml(ie.Html);
        //Test HTML Loads
        string test = html.DocumentNode.InnerHtml;
        HtmlNode node = html.DocumentNode.SelectSingleNode(xpath);

Node always returns NULL.


I believe some versions of IE XPath are 0 based... thus you would need to subtract 1 from each "array" index.

0

精彩评论

暂无评论...
验证码 换一张
取 消