HTML Parsing

  • Thread starter Thread starter Sam Low
  • Start date Start date
S

Sam Low

I have some HTML text. How do I push it into the document object of
InternetExplorer.Application?

My goal: I want an easy way to extract all the IMG links in the HTML text.

Thanks in advance.
 
You either use Navigate method and navigate to file with file:// protocol or
use document property and its write method or document.body.innerHTML:

Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank" 'this line is important
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 200
objExplorer.Left = 0
objExplorer.Top = 0
Do While (objExplorer.Busy)
WScript.Sleep 200
Loop
objExplorer.Visible = 1

objExplorer.document.write("<HTML><BODY>Hello from WSH</BODY></HTML>")
WScript.Sleep 5000
objExplorer.Quit()

//------------------------------------
Regards,
Vassiliev V. V.
http://www-sharp.com -
Scripting/HTA/.Net Framework IDE
 
Thanks. I haven't tried this, so document.write("<img id='pic1'
src='xxx.jpg'>") will allow me to reference document.pic1?

Sam
 
On the next line after document.write you may need to use document.all.pic1
(not just document.pic1):

Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=400
objExplorer.Height = 200
objExplorer.Left = 0
objExplorer.Top = 0
Do While (objExplorer.Busy)
WScript.Sleep 200
Loop
objExplorer.Visible = 1

objExplorer.document.write("<img id='pic1' src='xxx.jpg'>")
MsgBox objExplorer.document.all.pic1.outerHTML
'WScript.Sleep 5000
objExplorer.Quit()

//------------------------------------
Regards,
Vassiliev V. V.
http://www-sharp.com -
Scripting/HTA/.Net Framework IDE
 
Thanks, it worked for me. I used:

Set pics = objExplorer.document.all.tags("IMG") to look for all the picture
links.


Sam
 
document has also images collection (at least in IE):

objExplorer.document.images

//------------------------------------
Regards,
Vassiliev V. V.
http://www-sharp.com -
Scripting/HTA/.Net Framework IDE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top