1

I know that it's possible to launch a web browser on a specific website with batch - but I want to save the content of the viewed website.

It will be a result set of a query script inside of this browser, and the result will look like:

header2;header2;header3

result1;result2;result3

So basically like a CSV.

I know how to open a browser, but I don't know if the other part is possible.

Martin
  • 47
  • 7

1 Answers1

2

save this as .bat (it's a .bat/.vbs hybrid) and replace with your address/output file:

:sub echo(str) :end sub
echo off
'>nul 2>&1|| copy /Y %windir%\System32\doskey.exe '.exe >nul


'& rem cscript /nologo /E:vbscript %~f0 "%~1" > "%~2"
'& cscript /nologo /E:vbscript %~f0 "http://www.google.bg/" >google.txt
'& pause
'& rem "'.exe"
'& exit /b



'You must turn-off certificate mismtatch warnings"
'internet explorer -> tools -> options -> advanced tab -> uncheck certificates mismatch

'you must also disable ActiveX prompting:
'internet explorer -> tools -> options -> security -> custom level -> automatic prompt for activeX: disabled




URLToExtract=WScript.Arguments.Item(0)


SaveToFile=""



'prepare objects

Dim  objIE, strAllText
Set objIE = CreateObject( "InternetExplorer.Application" )
objIE.Visible = False

Set objFSO = CreateObject("Scripting.FileSystemObject")

'extract document data function

Sub URLExtract(strURL,objIE,strAllText,strFilePath,objFSO)
    'WScript.echo strFilePath
    Dim blnTimedOut, i      
    objIE.Navigate2 strURL

    Do While objIE.Busy
        WScript.Sleep 150
        i = i + 1
        ' Time out after 10 seconds
        If i > 100 Then
            blnTimedOut = True
            Exit Do
        End If
    Loop

    If Not blnTimedOut Then strAllText = objIE.Document.Body.InnerText
    'If Not blnTimedOut Then Wscript.echo objIE.Document.Body.outerHTML
    'If Not blnTimedOut Then Wscript.echo objIE.Document.Body.innerHTML
    'strAllText=Escape(strAllText)
    'Set Writer = objFSO.OpenTextFile(strFilePath, 2,true,0)
    WScript.Echo strAllText
    'Writer.WriteLine(strAllText)
    'Writer.Close

end SUB



Call URLExtract(URLToExtract,objIE,strAllText,SaveToFile,objFSO)

objIE.Quit
Community
  • 1
  • 1
npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Thank you! It worked! (sorry for the late answer, had been switched on another project and after I had to to some pre-work. One more question: why does the batch file create a "'.exe" File? Is it because of the third line where you copy some exe from the Windows folder? Thanks for your help! – Martin Jan 27 '14 at 15:14
  • 1
    @Martin you can check the link in the brackets.There's explained.In brief this is my 'clever' "hack" for creating hybrid batch\vbsripts.It creates an `'exe` form `doskey.exe` .`doskey` has no effect in batch and is a comment in `Vbscript`. so `'&..` is a comment in VBSCRIPT and execute `doskey and the next command in batch`.As `doeskey` does do nothing only the second part has meaning. – npocmaka Jan 27 '14 at 15:23
  • Hey, I understood. Thanks. Is it possible to access the gained data within the batch and process them? The website will show a CSV with folders and files, I need to create the folders and copy the files into them. – Martin Jan 27 '14 at 16:41
  • I already have a script to process a CSV which is given to a batch. Now with your Script I access a Website which already shows the CSV. So on your script a textfile is given out - I have to skip that part and directly process the contents of the opened website. For example: `ID;Type;Name;Path` `ID;Type;Name;Path` Type will be Folder or File. Like I said I already have the code for processing that - but how can I give the variable to batch? – Martin Jan 27 '14 at 17:05
  • Unfortunetly google let me down on this - because passing variable from vbs to batch inside only returns two seperated scripts - so I don't know.. Is it possible to pass more than one website and call the function multiple times? Do I have to increase the %~f0 parameter for that and call the function with Arguments.Item(1)? – Martin Jan 28 '14 at 08:51
  • Yes you can.the `%~f0` is the script itself and you should not touch it. `cscript /nologo /E:vbscript %~f0 "http://www.google.bg/" >google.txt` call this line so many times as you want with different links.... – npocmaka Jan 28 '14 at 09:08
  • But how is that possible? Is it some kind of a loop? Because you only passed `Argument.Item(0)` to the URLToExtract variable.. – Martin Jan 28 '14 at 09:30
  • by the way - do you have an idea about the parsing variable part? If you don't think there's a possiblity than it's okay - but right now I really don't have the knowledge of batch to resolve this. If you need more information than I can give you all that I have. – Martin Jan 28 '14 at 09:37
  • `Argument.Item(0)` is the web site to process.You can upload a document somewhere it more information , but if it's require more programing I don't know when I'll be ready. – npocmaka Jan 28 '14 at 10:08
  • Ok, I figured out a new way. I will call your script from another batch to get results from multiple Websites - and then call another batch again to process the textfiles that have been created. That will work the same. Your script builds the main part so I give all my thanks to you! Thank you! – Martin Jan 28 '14 at 10:16