Converting a HtmlAgilityPack.HtmlNode to a string

c# html html-agility-pack string

Question

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.

Accepted Answer

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);
    }
}



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