|
-
Sep 27th, 2005, 01:49 PM
#1
Thread Starter
Lively Member
[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?
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 02:18 PM
#2
Re: WebBrowser control - get source code of HTML page?
load the page into an HTML object, then use the .documentElement.innerHTML method..
-
Sep 27th, 2005, 02:23 PM
#3
Thread Starter
Lively Member
Re: WebBrowser control - get source code of HTML page?
How is this supposed to be done?
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 02:31 PM
#4
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...
-
Sep 27th, 2005, 02:39 PM
#5
Thread Starter
Lively Member
Re: WebBrowser control - get source code of HTML page?
I need to use a AnWebBrowser control
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 02:39 PM
#6
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...
Last edited by gigemboy; Sep 27th, 2005 at 02:42 PM.
-
Sep 27th, 2005, 02:43 PM
#7
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
-
Sep 27th, 2005, 02:49 PM
#8
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
-
Sep 27th, 2005, 02:51 PM
#9
Thread Starter
Lively Member
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
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 02:55 PM
#10
Re: WebBrowser control - get source code of HTML page?
-
Sep 27th, 2005, 03:01 PM
#11
Thread Starter
Lively Member
Re: WebBrowser control - get source code of HTML page?
It's the same - only what's between <head>
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 03:04 PM
#12
Thread Starter
Lively Member
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
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 03:07 PM
#13
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???
-
Sep 27th, 2005, 03:08 PM
#14
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?
-
Sep 27th, 2005, 03:09 PM
#15
Thread Starter
Lively Member
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...
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 03:10 PM
#16
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.
-
Sep 27th, 2005, 03:11 PM
#17
Thread Starter
Lively Member
Re: WebBrowser control - get source code of HTML page?
That's the mistake, in fact
"Imagination is more important than knowledge!" Albert Einstein
If you like this answer/question, please rate it! Thank you!
-
Sep 27th, 2005, 03:16 PM
#18
Re: [RESOLVED] WebBrowser control - get source code of HTML page?
lol.. I had a feeling it was
-
Nov 30th, 2005, 04:15 AM
#19
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|