load from browser with htmlagilitypack

browser c# html-agility-pack web

Question

At the moment, I'm trying to run example from the htmlaglitypack official site, but this code is broken: http://html-agility-pack.net/from-browser

I want to extract content after script completing. My code:

private void button1_Click(object sender, EventArgs e)
    {
        string url = "http://html-agility-pack/from-browser";
        var web2 = new HtmlWeb();
        var doc2 = web2.LoadFromBrowser(url, html =>
         {
             return !html.Contains("<div id=\"uiDynamicText\"></div>");
         });
        var t2 = doc2.DocumentNode.SelectSingleNode(".//div[@id='uiDynamicText']");

        listBox1.Items.Add("Text 2: " + t2.InnerHtml + t2.OuterHtml);
    }

t2 stay as null. What is the problem?

1
1
3/7/2018 10:43:55 AM

Accepted Answer

the HAP code also has wrong URL (missing ".net") so the code should read string url = "https://html-agility-pack.net/from-browser";

0
6/30/2019 7:51:35 AM

Popular Answer

The website says to use:

var t2 = doc2.DocumentNode.SelectSingleNode("//div[@id='uiDynamicText']").InnerText;

You are using different code:

var t2 = doc2.DocumentNode.SelectSingleNode(".//div[@id='uiDynamicText']");

Which explains why, with your code, t2 is null.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow