Danil Jw
Danil Jw

Reputation: 25

load from browser with htmlagilitypack

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?

Upvotes: 2

Views: 3646

Answers (2)

Dick Baker
Dick Baker

Reputation: 71

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

Upvotes: 2

mjwills
mjwills

Reputation: 23819

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.

Upvotes: 2

Related Questions