2016-11-08 61 views
-1

我得到了一個要求,需要從網站獲取少量內容,我必須使用批處理腳本將其保存在.txt文件中。如何使用批處理腳本讀取網站的內容?

@echo off 
    echo.>"D:\Jai\dblank.txt" 

通過上面的批處理代碼,我只能用這個,我想給在.txt文件瀏覽器內容一起創建一個位置的文件。我對批處理腳本非常陌生。

回答

0
Set Arg = WScript.Arguments 
set WshShell = createObject("Wscript.Shell") 
Set Inp = WScript.Stdin 
Set Outp = Wscript.Stdout 

if LCase(Arg(0)) = "web" or LCase(Arg(0)) = "http" then 
    HttpGet 
Elseif LCase(Arg(0)) = "remhtml" or LCase(Arg(0)) = "tags" then 
    RemoveHTMLTags 
End If 


Sub HttpGet 
On Error Resume Next 
    Set File = WScript.CreateObject("Microsoft.XMLHTTP") 
    File.Open "GET", Arg(1), False 
    File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)" 
    File.Send 
    txt=File.ResponseText 
    'Putting in line endings 
    Outp.write txt 
    If err.number <> 0 then 
     Outp.writeline "" 
     Outp.writeline "Error getting file" 
     Outp.writeline "==================" 
     Outp.writeline "" 
     Outp.writeline "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description 
     Outp.writeline "Source " & err.source 
     Outp.writeline "" 
     Outp.writeline "HTTP Error " & File.Status & " " & File.StatusText 
     Outp.writeline File.getAllResponseHeaders 
     Outp.writeline LCase(Arg(1)) 
    End If 
End Sub 

Sub RemoveHTMLTags 
    Set ie = CreateObject("InternetExplorer.Application") 
    ie.Visible = 0 
    ie.Silent = 1 
    ie.Navigate2 "file://" & FilterPath & "Filter.html" 
    Do 
     wscript.sleep 50    
    Loop Until ie.document.readystate = "complete" 
    ie.document.body.innerhtml = Inp.readall 
    Outp.write ie.document.body.innertext 
' ie.quit 
End Sub 

要使用

一般使用

過濾器是在命令提示符下使用。 Filter.vbs必須使用cscript.exe運行。如果你只是輸入過濾器,它將運行一個批處理文件,這將自動執行此操作。

filter subcommand [parameters] 

過濾器只能讀取和寫入標準輸出。這些僅在命令提示符下可用。

filter <inputfile >outputfile 
filter <inputfile | other_command 
other_command | filter >outputfile 
other_command | filter | other_command 

網絡

filter web webaddress 
filter ip webaddress 

從網上下載一個文件,並將其寫入到標準輸出。

webaddress - a web address fully specified including http:// 

獲取微軟的主頁

cscript //nologo filter.vbs web http://www.microsoft.com 

標籤

filter tags 

刪除HTML標籤從文本。

cscript //nologo filter.vbs web http://www.microsoft.com | cscript //nologo filter.vbs tags 
相關問題