0

I'm new to this Windows Metro stuff and I am trying to make a application that grab a html page from the web and fills some fields in the app.

Right now I'm just trying to figure out how to grab a page and send pure HTML to a textbox.

I've setted up a button (that runs the next function once clicked) and a textbox to display the information.

The function executed by the button is this:

private void fetch_websites(object sender, RoutedEventArgs e)
{
    String url = "http://www.google.com/";
    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(url);
    this.content_block.Text = doc.DocumentNode.OuterHtml;
}

The problem is that the displayed information is not the Html code but the "url" string.

(I've seen this code in here and here)

Community
  • 1
  • 1
Bruno Camarneiro
  • 545
  • 4
  • 19

2 Answers2

1

LoadHtml method takes the html content to parse. It doesn't automatically loads the url. Use HtmlAgilityPack's HtmlWeb class or HttpClient / WebClient / HttpWebRequest classes to get the page from your url.

L.B
  • 114,136
  • 19
  • 178
  • 224
0

Got it!

    private async void fetch_websites(object sender, RoutedEventArgs e)
    {
        String url = "http://www.google.com/";
        HtmlWeb page = new HtmlWeb();
        HtmlDocument doc = await page.LoadFromWebAsync(url);
        //doc.LoadHtml(url);
        this.content_block.Text = doc.DocumentNode.OuterHtml;
    }
Bruno Camarneiro
  • 545
  • 4
  • 19