2
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.

4
  • 1
    What does usercon expect? A URL, the hyperlink text, or something else? Commented Mar 10, 2017 at 0:10
  • A string(I am filling the required characters) Commented Mar 10, 2017 at 2:19
  • 1
    @Beall619 String that represent what? URL, HTML tag, or what? Please give as an example of correct value for link.. Commented Mar 10, 2017 at 3:44
  • This will be a web crawler "eventually". A correct link would be "stackoverflow.com" Commented Mar 10, 2017 at 3:48

1 Answer 1

3

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);
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

That works however im getting more than just links in the output. I dont know much about html however there is syntax in the output.
Im sure i can make a filter for correct formats. Other than that what you suggested works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.