print the HTMLAgilityPack source code

beautifulsoup c# html html-agility-pack python

Question

Coming from a python background, I'm fresh to C#. This has been challenging for me to understand. I can perform the following in Python by using beautifulsoup:

from bs4 import BeautifulSoup
import requests
r = requests.get('http://stackoverflow.com').content
soup = BeautifulSoup(r).prettify
print soup

This retrieves the stackoverflow.com source material and writes it to the terminal. I am unable to do this in C#.

        var webGet = new HtmlWeb();
        var document = webGet.Load("http://stackoverflow.com");
        Console.WriteLine(document);

It simply prints the type of var document, therefore this is ineffective. Anyone who is capable of doing this? I'm attempting to learn C# by converting one of my Python projects, so any help would be much appreciated.

1
1
3/17/2012 2:57:58 PM

Accepted Answer

Apply theOuterHtml possession of theDocumentNode :

var webGet = new HtmlWeb();
var document = webGet.Load("http://stackoverflow.com");
Console.WriteLine(document.DocumentNode.OuterHtml);
4
3/17/2012 3:20:08 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow