load from browser with htmlagilitypack

browser c# html-agility-pack web

Question

I'm now attempting to run an example from the official htmlaglitypack website, but the code is broken: http://html-agility-pack.net/from-browser

After the script is finished, I want to extract the content. My key:

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 remain null. What's the issue?

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

Accepted Answer

Additionally, the HAP code's URL is incorrect (it lacks ".net"), thus the code should read the string "https://html-agility-pack.net/from-browser";

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

Popular Answer

The website advises using:

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

You're using an alternative code:

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

That is why, using 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