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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbs - access HTML through Internet Explorer

Status
Not open for further replies.

Beard36

Programmer
Sep 4, 2003
69
GB
What I want to do is access the source of web page and pick out some of the information with vbs.

I have tried using something along the lines of -

Set objExplorer = createobject("internetexplorer.application")
objExplorer.Visible = False
objExplorer.navigate "
While (objExplorer.readystate <> 4)
Wscript.Sleep 10
Wend

strHTML = objExplorer.document.body.outerHTML
objExplorer.quit

arrHTML = Split(strHTML, vbCrLf)
For intLoop = 0 to UBound(arrHTML, 1)
WScript.Echo arrHTML(intLoop)
Next


which seems to get all of the data. However, it doesn't appear the same as if I browsed to the page and went through View / Source. There seem to be extra tags, and whitespace is all rearranged.

Can anyone tell why this is, and if it's possible to do similar but to get the source as it appears when I view it in notepad from Internet Explorer (or even save the page to my hard disk and open it in Notepad)?

If anyone could explain what's going on, it would be greatly appreciated!

Cheers,
Dan.
 
Hello Beard36,

It is because you can captured the .document.body.outerHTML. In order to grab the whole stuff, use microsoft.XMLHTTP component (or its successor msxml2.XMLHTTP etc.)
Code:
with createobject("microsoft.XMLHTTP")
   .open "GET", "[URL unfurl="true"]http://www.website-to-access.html",[/URL] false
   .send()
   sSrc = .responsetext
end with
With sSrc you can saved it to a file (of .htm) to view or to parse. Or, use split to view. But, if you split against vbcrlf or even vbcr, prepare to get nasty surprise of too big echo screen that you don't have ok button to push! (You may split against something like "." to have a feel.) Better to save to some text file then do something starting from there.

regards - tsuji
 
That's terrific!
Thanks a lot.

BTW, where would I have been able to find out which object to use? I had been looking round the 'net looking for such information but drawing a blank.

Cheers,
Dan.
 
Beard36,

No reason drawing a blank! Only reason is nobody yet show or not motivated yet emerge that your attention get sufficiently focused. Do again some search, you will amaze how one can be so inattentive in the past.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top