我有一个要求,需要从网站获取一些内容,我必须使用批处理脚本将其保存在.txt文件中。
@echo off
echo.>"D:\Jai\dblank.txt"
通过使用上面的批处理代码,我只能在一个位置创建一个文件,我想在该.txt文件中给出浏览器内容。我是批处理脚本的新手。
答案 0 :(得分:1)
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
使用
一般用途
过滤器用于命令提示符。必须使用cscript.exe运行Filter.vbs。如果您只是输入过滤器,它将运行一个自动执行此操作的批处理文件。
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://
示例强>
获取Microsoft的主页
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