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?

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.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why