using VB.net or c#, How do I get the generated HTML source?
To get the html source of a page I can use this below but this wont get the generated source, it won\'t c
You can use this code:
webBrowser1.Document.Body.OuterHtml
You can use WebKit.NET
Look here for official tutorials
This can not only grab the source, but also process javascript through the pageload event.
webKitBrowser1.Navigate(MyURL)
Then, handle the DocumentCompleted event, and:
private documentContent = webKitBrowser1.DocumentText
Edit - This might be the better open source WebKit option: http://code.google.com/p/open-webkit-sharp/
Just put a webbrowser
control to your form and you flowing code:
webBrowser1.Navigate("YourLink");
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
string htmlcode= webBrowser1.Document.Body.InnerHtml;//Or Each Filed Or element..//WebBrowser.DocumentText
}
Edited
for getting also html code that generated dynamically by java script code you have two way:
webBrowser1_DocumentCompleted
EventStringBuilder htmlcode = new StringBuilder(); foreach (HtmlElement item in webBrowser1.Document.All) { htmlcode.Append( item.InnerHtml); }
document.documentElement.innerHTML
and using InvolkeScript Function To Return Result:var htmlcode = webBrowser1.Document.InvokeScript("javascriptcode");