Microsoft.httpRequest and ADODB.Stream
Hello Guys, i have a vbs script that uses adodb.stream and httpRequest to extract data from a page into an excel spreadsheet. It happens that when theres is no data to extract, the script returns the html code of the page. I'd like to return something like "No data available" instead, but i cant find a way. I'm thinking that i may have to approach the hole thing differently to do it. Anyway, here is the script:
Code:
'=================================================================================================================
Function exportReport(strReportURL)
'On Error Resume Next
'setup an HTTP POST to the report URL
Set http = CreateObject("Microsoft.XmlHttp")
http.open "Post", strReportURL, False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 'required header
'fake the webpage into thinking EXPORT has been clicked. The following line initiates the POST, Export is a link to export the data to excel
http.send "export=yes"
oStream.write http.responseBody 'write the binary response from our POST above to the stream
End Function
'=================================================================================================================
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.OpenTextFile("advs.txt", 1)
'save binary response using ADODB.Stream
Set oStream = createobject("ADODB.Stream")
oStream.type = 1 'adTypeBinary
oStream.open
Do while ( not MyFile.AtEndOfStream )
adv = MyFile.Readline()
url = "http://www.someweb.com/query?=" & adv
wscript.echo "Processing... " & adv
exportReport url
Loop
oStream.savetofile "metrics.cvs", 1
oStream.Close
MyFile.Close
Set WshShell = Nothing
Set fso = Nothing
Set MyFile = Nothing
Any tips is greatly appriciated, thank you in advance.
Best Regards :D
Re: Microsoft.httpRequest and ADODB.Stream
What does the page return when there is data to extract and how do you distinguish between the two?