Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I programatically read source code from the webbrowser ctrl?

Status
Not open for further replies.

AncientTiger

Programmer
Jul 5, 2001
238
0
0
US
This is probably a silly question, but I'm just starting out in VB so please bear with the newbie ;)

I've set up a form that contains a Webbrowser control. Now, when I type in a URL and click a button, that URL is loaded in the webbrowser. Once that webpage is loaded, how can I load the page contents into something like a dimmed array?
Something like MyHtml(codelinenumber) ?

This is a really cool forum by the way.... glad I found it!
Thanks,
AT
 
Use the Inet-control.
This way you have the html-code in one string (you could also use a byte array).
If you want to put each line in a array-element, you could search the string voor vbCrLf, that way you know when you're at the end of a line (might not work perfect, don't know how well the htm-code is received), and then put it in the array.

Private Function GetHtmCode() As String

Dim lsRetval As String

Inet1.Protocol = icHTTP
Inet1.URL = " lsRetval = Inet1.OpenURL(Inet1.URL, icString)
Do While Inet1.StillExecuting
Loop
GetHtmCode = lsRetval

End Function

Remedy
 
Now I have to admit that I have no idea what the Inet control is but it seems to me that one would have to download the page twice, once for the webbrowser control an once for the Inet control. I have just finished part of a project that also uses the HTML source of a web page. The way I accessed the HTML source was using
Code:
webbrowser1.document.body.innerhtml
. Perhaps you would be able to use that and chop it up into lines using the Split() function so it might look something like this:
Code:
Dim MyHTML() as String

MyHTML() = Split(webbrowser1.document.body.innerhtml, vbCrLf)
Please note I have not tried this and do not know if it will work for sure. But that is what I would try. Also I am not completely sure that the
Code:
webbrowser1.document.body.innerhtml
exposes the whole source of the web page, so you might want to check that. It worked for what I was doing.

Schmerk
 
The webbrowser has a document object that is very useful - but a little bit tricky (but not as bad as the Internet control). It's fairly well documented on microsoft's site.

You will need to add a reference to Internet HTML object (or something like that) in your project. You can then do something like this

Dim Internetdoc as HTMLdocument
set Internetdoc = webbrowser1.document

OnScreenText = Internetdoc.innertext
OffScreenHTML = Internetdoc.innerHTML

Don't quote me on the specific property names, but they're close enough that you should be able to figure it out. There are a lot of other properties and methods in the document object that are useful. Give it a try.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top