# VBScript to open webpage and save the text contents into a variable



## saxah999 (Nov 4, 2011)

Hi! I have been dealing with so many limmitations of HTA using VBScript and I badly need rescueing  I'm creating HTA applications using VBScript and I can't opt to use any other languages or work arround since I don't have time to learn new languages and I'm trying to use these softwares at the office. I cant install any other softwares to use since the IT Department is strict when it comes to installing and downloading non work-related files. Though my softwares are useful, IT dept wont agree with me.

One of the problems I'm having right now is creating a VBScript on HTA that will open an IE browser, get all the text content in it, then save it to a variable. Something like "a = webpage.texts". I have searched google and got frustrated with the work arrounds other forums show. Is there any way to achieve this using just vbscript on HTA and using a non-admin login to a windows7 computer? I was able to use this code but for some reason it only worked for a while, then it stopped working (Showing error). I'm not sure if I may have changed something on the code. Please reply if you have any solutions 

Function NetSolWhoIs(myDomain, myTimeOut)
Set fukie = CreateObject("InternetExplorer.Application")
fukie.Visible = false
fukie.Navigate2 "https://www.networksolutions.com/whois/registry-data.jsp?domain=" & Trim(myDomain)
WaitLang = window.setInterval("relaylang",3000)
End Function

Function relaylang
msgbox fukie.Document.Body.InnerText '<<<<< *THIS SHOWS UNSPECIFIED ERROR* (CODE-0)
document.GetElementByID("PingSummary").value = document.GetElementByID("PingSummary").value & vbcrlf & mid(fukie.Document.Body.InnerText,instr(fukie.Document.Body.InnerText,"Domain Name:"),instr(fukie.Document.Body.InnerText,"<<<")-instr(fukie.Document.Body.InnerText,"Domain Name:"))
window.clearInterval(WaitLang)
end Function


----------



## saxah999 (Nov 4, 2011)

Nobody seem to reply on this website forum.  I tried something else though. I placed an error handler instead to avoid getting error pop-ups but it may not be a good idea since I'm using on error resume next, which reads next line and ignores error messages (some important linecodes may get bypassed).


----------



## Rollin_Again (Sep 4, 2003)

Is this true VB script or are you talking about a VBA macro? I tried the code you posted and it works fine for me.

Rollin


----------



## saxah999 (Nov 4, 2011)

It's VBScript, not the VBA. I'm using HTA(HTML App). Here's what I've noticed, sometimes it works, sometimes it doesn't. I think it fails if the IE page state is not yet ready when it read the line "fukie.Document.Body.InnerText". If that is the case then I may be doomed.0~0 I have no way to counter that since I have no idea how to do sleep or wscript.sleep using VBS on HTA, for some reason, it doesnt know what WSCRIPT is. Probably not installed on my computer. Also I dont have any way to put timer on HTA so it would wait until IE becomes ready to give "fukie.Document.Body.InnerText".


----------



## Rollin_Again (Sep 4, 2003)

saxah999 said:


> for some reason, it doesnt know what WSCRIPT is.


Is an error being thrown?

Rollin


----------



## saxah999 (Nov 4, 2011)

For wscript? Yes, it pops up "Object Required wscript" when using the code "wscript.sleep". I think I found the solution though. It seems that, depending on your internet connection speed, if the .navigate2 has not fully opened the page, the document.body.innertext code gets an error since it has not captured the texts on the site yet due to the page not beeing fully loaded. I found out about the code to loop until .navigate2 becomes ready and not busy. I do not seem to get the error so far.

I'd like to thank you Rollin_Again for helping me out. Is this forum new and active by the way? I did not get much replies so I thought there were no more people in here


----------

