Results 1 to 2 of 2

Thread: WebBrowser control - get all html including head content

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2003
    Posts
    74

    WebBrowser control - get all html including head content

    I'm using a WebBrowser control to get the HTML code of a webpage. But, right now it only returns me the contents of the body. How can I also grab the head content (I want to javascript too).

    This is what I do now: (wbWeb is my WebBrowser control, and strhtml is the web page HTML I want)



    wbWeb.Navigate(psURL)

    Do While wbWeb.ReadyState <> 4 '= READYSTATE_COMPLETE
    Application.DoEvents()
    Sleep(500)
    Loop

    strhtml = wbWeb.Document.body.outerhtml




    Any help is appreciated! Thanks in advance!

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you should be using DocumentElement not Body , also if you try typing wbWeb.Document.body.outerhtml with Option Strict turned on it'll error , you need to add a reference to the mshtml dll.
    here's an example ...
    VB Code:
    1. '/// you must add a reference to the Microsoft html object library.
    2.  
    3.         AxWebBrowser1.Navigate("about:home")
    4.         While Not AxWebBrowser1.ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE
    5.             Application.DoEvents()
    6.         End While
    7.  
    8.         Dim objHtml As mshtml.HTMLDocumentClass = DirectCast(AxWebBrowser1.Document, mshtml.HTMLDocumentClass)
    9.         Dim strHtml As String = objHtml.documentElement.outerHTML
    10.  
    11.         MessageBox.Show(strHtml)
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width