Beall619
Beall619

Reputation: 65

Converting a HtmlAgilityPack.HtmlNode to a string

private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show("In devolopment","Error", MessageBoxButtons.OK);
            HtmlAgilityPack.HtmlWeb hw = new HtmlAgilityPack.HtmlWeb();
            HtmlAgilityPack.HtmlDocument doc = hw.Load("https://www.stackoverflow.com");
            foreach (HtmlAgilityPack.HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
            {
                usercon(link);
            }

        }

.

public void usercon(string toprint)
        {
            richTextBox1.Text += "\r\n";
            richTextBox1.Text += toprint;
            //richTextBox1.
        }

I need to be able to convert link to a string so that in can be used in the function usercon

This is my first time using the HtmlAgilityPack.

Upvotes: 2

Views: 6906

Answers (1)

Markus
Markus

Reputation: 761

According to the source code found here: https://htmlagilitypack.codeplex.com/SourceControl/latest#Release/1_4_0/HtmlAgilityPack/HtmlNode.cs
See also (new) documentation: http://html-agility-pack.net/outer-html HtmlNode has an OuterHtml property and its source on GitHub.

private void button2_Click(object sender, EventArgs e)
{
    MessageBox.Show("In devolopment","Error", MessageBoxButtons.OK);
    HtmlAgilityPack.HtmlWeb hw = new HtmlAgilityPack.HtmlWeb();
    HtmlAgilityPack.HtmlDocument doc = hw.Load("https://www.stackoverflow.com");
    foreach (HtmlAgilityPack.HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
    {
        usercon(link.OuterHtml);
    }
}

Upvotes: 3

Related Questions