[RESOLVED] WebBrowser control - get source code of HTML page?
Hello,
I'm writing a small app, but I have a problem. The app has a WebBrowser control (AxWebBrowser). I'm using the Naviagate2 method to make the control show a web page. How can I get the source code of the viewed page?
Re: WebBrowser control - get source code of HTML page?
load the page into an HTML object, then use the .documentElement.innerHTML method..
Re: WebBrowser control - get source code of HTML page?
How is this supposed to be done?
Re: WebBrowser control - get source code of HTML page?
hmm I've done a program that was pulling the innertext (innerhtml is just another method that is similar) from an Internet Explorer window using Window Handles... not by using the AxWebBrowser... if you want i can see about cleanin up the code a little and posting...
Re: WebBrowser control - get source code of HTML page?
I need to use a AnWebBrowser control
Re: WebBrowser control - get source code of HTML page?
Actually.. it's going to be overkill for what you need because its using API calls.. I'm assuming your program already has the HTML document being displayed, so just run that object's method...
VB Code:
Dim myHTMLDoc as HTMLDocument = (your html document)
Dim strHTML As String
strHTML = myHTMLDoc.documentElement.innerHTML.ToString
This requires a reference to mshtml, and the Imports mshtml at the top...
Re: WebBrowser control - get source code of HTML page?
you need to set a reference to MSHTML, this will give you the objects you need to access the HTML Source of a page.
AxWebBrowser.Document IS an htmldocument, but its represented as an OBJECT, because the webbrowser is being imported from COM.
So you need to do something like
VB Code:
Dim MyDoc As mshtml.HTMLDocument
MyDoc = CType(wb.Document, mshtml.HTMLDocument)
Debug.Write(MyDoc.documentElement.innerHTML)
where wb is the webbrowser control
Re: WebBrowser control - get source code of HTML page?
except yours won't work with option strict on..
but thank you for deleting your post.. as it wasn't really necessary.. but don't worry.. i don't take offense ;)
Re: WebBrowser control - get source code of HTML page?
OK kleinma, your suggestion worked but another problem poped out - it gets only what's between the <head> tags
Re: WebBrowser control - get source code of HTML page?
Re: WebBrowser control - get source code of HTML page?
It's the same - only what's between <head> :(
Re: WebBrowser control - get source code of HTML page?
In fact it gets only the code before <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> and puts <head> tags around this code
Re: WebBrowser control - get source code of HTML page?
Hmm I think something else is happening then... it doesn't "put" anything.. it just reports back the text... it showed head tags there because it found head tags there... sure you are referenceing the right object and nothing else is going on???
Re: WebBrowser control - get source code of HTML page?
try another HTML document to make sure its not just the current HTML you are working with.. perhaps it is not formed correctly or something like that?
Re: WebBrowser control - get source code of HTML page?
Oh, sorry my mistake - the page I was loading refreshed and loaded another page. I had to call this after the second page is loaded - now it worked :) Thanks for the help guys...
Re: WebBrowser control - get source code of HTML page?
also make sure you put this in the DocumentComplete event of the browser... if you put it on the navigatecomplete event, the page may not be fully loaded yet.
Re: WebBrowser control - get source code of HTML page?
That's the mistake, in fact ;)
Re: [RESOLVED] WebBrowser control - get source code of HTML page?
lol.. I had a feeling it was
Re: [RESOLVED] WebBrowser control - get source code of HTML page?
How can I put this html source code back to the browser web page?
Thanks