3

I have a webbrowser control. I navigate it to some address. When it loaded i want to pick only urls from inside this codes. Is it possible to handle the html like xml? If it is possible i can use othe DOM properties too. Any xml like ingredient container object to pass the html into it? Thank you.

NakedBrunch
  • 48,713
  • 13
  • 73
  • 98
Caglar Or
  • 31
  • 2

2 Answers2

4

Sounds like you need to use the HTML agility pack

Also see this other stack overflow question:

C# Is there a LINQ to HTML, or some other good .Net HTML manipulation API?

Doctor Jones
  • 21,196
  • 13
  • 77
  • 99
1

Yes, you can use MSHTML to navigate the DOM. You would need to add a reference to Microsoft.mshtml in your project. An example of using it to get all links in a document would be:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    HtmlDocument doc = webBrowser1.Document;

    foreach (HtmlElement element in doc.Links)
    {
        HTMLAnchorElement link = (HTMLAnchorElement) element.DomElement;
        Debug.WriteLine(link.href);
    }
}
Garett
  • 16,632
  • 5
  • 55
  • 63