I'm new to C# coming from a python background. I've had a hard time figuring this out. In python I can use beautifulsoup to do this:
from bs4 import BeautifulSoup
import requests
r = requests.get('http://stackoverflow.com').content
soup = BeautifulSoup(r).prettify
print soup
This gets the source content of stackoverflow.com, and prints it in to the console. I CANNOT figure out how to do this in C#.
var webGet = new HtmlWeb();
var document = webGet.Load("http://stackoverflow.com");
Console.WriteLine(document);
This does not work, it only prints the type of var document. Does anyone know how to do this? It would be much appreciated - I'm trying to learn C# by converting one of my python programs, just fyi.
Use the OuterHtml
property of the DocumentNode
:
var webGet = new HtmlWeb();
var document = webGet.Load("http://stackoverflow.com");
Console.WriteLine(document.DocumentNode.OuterHtml);