Monday, November 14, 2011

HowTo: Pretend you are working (While Text Browsing)

Commandline Web Browser (Just like lynx) using VbScript and IE API.

About the code: The code below will use the Internet Explorer API to load the top 20 stories from google news and choosing one of the article will load the document html of the target URL for you to be able to read news from your DOS command line. Best way to look like you are still working on a code while actually reading news without opening any web browsers :p

Requirements: IE 6++

Code Snippet:

Sub Loadnews()
Dim arrTestArray()
Dim urlSelect
intSize = 0
Dim rInterval:rInterval=60
Dim sTime:sTime = Now
Set ie = CreateObject("InternetExplorer.Application")
with ie
.visible = 0
.navigate "http://news.google.com/"
WScript.StdOut.Write vbcrlf & vbtab & "Loading Top Stories for @ " & Now
while .busy
WScript.StdOut.Write "."
WScript.Sleep 1000
wend
WScript.Echo vbcrlf & vbtab & "elapsed : " & datediff("s",sTime,Now) & " secs"
WScript.Echo vbtab & "next refresh: " & dateadd("s",rInterval,Now) & " secs" & vbcrlf
dim ctr:ctr=1
Set newsTitle = .Document.getElementsByTagName("a")
For each xTag in newsTitle
If instr(xTag.InnerHTML,"titletext") >0 then
WScript.Echo vbcrlf & vbtab & ctr & ". " & xTag.InnerText & _
"..." & vbcrlf & vbTab & "[" & xTag & "]"
ctr = ctr + 1
ReDim Preserve arrTestArray(intSize)
arrTestArray(intSize) = xTag
intSize = intSize + 1
If ctr >20 Then Exit For
End If
Next
end with
ie.quit
Set ie = nothing
Dim sleepctr:sleepctr=1
WScript.StdOut.Write vbcrlf & vbtab & "Choose an article #: "

urlSelect = WScript.StdIn.ReadLine
Set ie = CreateObject("InternetExplorer.Application")
Dim tgt:tgt=arrTestArray(urlSelect-1)
with ie
.navigate tgt
WScript.StdOut.Write vbcrlf & vbtab & "Loading [URL]..." & arrTestArray(urlSelect-1)
while .busy
WScript.StdOut.Write "."
WScript.Sleep 1000
wend
WScript.Echo .Document.Body.InnerText
end with
WScript.StdOut.Write vbcrlf & vbtab & "Press any key to continue..."
jcontinue = WScript.StdIn.ReadLine

End Sub


Screen grab:



If at first you fail, call it version 1.0