Get the final generated html source using c# or vb.net

前端 未结 3 1582
野的像风
野的像风 2020-11-27 22:25

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

相关标签:
3条回答
  • 2020-11-27 22:53

    You can use this code:

    webBrowser1.Document.Body.OuterHtml
    
    0 讨论(0)
  • 2020-11-27 23:02

    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/

    0 讨论(0)
  • 2020-11-27 23:02

    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:

    1. run flowing code after webBrowser1_DocumentCompleted Event
     StringBuilder htmlcode = new StringBuilder();
                foreach (HtmlElement item in webBrowser1.Document.All)
                {
                    htmlcode.Append( item.InnerHtml);
                }
    
    1. write a javascript code for returning document.documentElement.innerHTML and using InvolkeScript Function To Return Result:
       var htmlcode = webBrowser1.Document.InvokeScript("javascriptcode");
    
    0 讨论(0)
提交回复
热议问题