批处理 - 启动Internet Explorer并将网站内容保存到脚本/变量/数组中

时间:2014-01-13 12:02:59

标签: javascript batch-file csv browser

我知道可以在批量的特定网站上启动网络浏览器 - 但我想保存所查看网站的内容。

它将是此浏览器内部查询脚本的结果集,结果如下所示:

header2;header2;header3

result1;result2;result3

所以基本上就像一个CSV。

我知道如何打开浏览器,但我不知道其他部分是否可行。

1 个答案:

答案 0 :(得分:2)

将其另存为.bat(it's a .bat/.vbs hybrid)并替换为您的地址/输出文件:

: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