Reputation: 25584
I'm new to c#. I need to do a script to get the HTML content of a webpage. Where I can get examples on how to do this? I have searched here but I can't find.
PS: Sorry for my dab english.
Best Regards,
Upvotes: 1
Views: 1597
Reputation: 243116
Look at the WebClient
class. The DownloadString
method returns a content of a page as a string:
var wc = new WebClient();
var html = wc.DownloadString("http://stackoverflow.com");
If you also want to parse the downloaded HTML, then you can take a look at HTML Agility Pack. It allows you to parse the HTML into a tree-like structure (similar to XmlDocument
) and you can use XPath to find elements in the document etc. It is much better approach then using regular expressions or parsing the content yourself.
Upvotes: 6