1

我有多个网页需要打开并将信息(只是文本)保存到每个网页的新文件中。我在 VBScripts 方面完全没有经验。但是,我一直在寻找几天,这是我到目前为止收集到的:

function download(sFileURL, sLocation, async)
  set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
  objXMLHTTP.open "GET", sFileURL, async
  on error resume next
  objXMLHTTP.send()
  if err.number = 0 then
    do until objXMLHTTP.Status = 200
     wscript.echo objXMLHTTP.Status
     wcript.sleep(200)
  loop
  if objXMLHTTP.Status = 200 Then
    set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    
    set objFSO = Createobject("Scripting.FileSystemObject")
    If objFSO.Fileexists(sLocation) Then objFSO.DeleteFile sLocation
    Set objFSO = Nothing
    objADOStream.SaveToFile sLocation
    objADOStream.Close
    set objADOStream = Nothing
    download = true
   end if
 else
   download = false
 end if
   set objXMLHTTP = Nothing
 end function

 if download("http://books.google.com/books/feeds/volumes?q=isbn", "test.txt", false) then
   wscript.echo "download ok"
 else
   wscript.echo "download did not work"
 end if

我怎样才能改变

if download("http://books.google.com/books/feeds/volumes?q=isbn", "test.txt", false)

从文本文件中的列表中读取,并保存为 test00, test01, test02,...

先感谢您

4

1 回答 1

2

这是最简单的代码,应该可以满足您的需要。

Set objFSO = CreateObject("Scripting.FileSystemObject")
ListFile = "D:\list.txt"
Set objFile = objFSO.OpenTextFile(ListFile)
FileNumber = 0
Do Until objFile.AtEndOfStream
    URLFromList = objFile.ReadLine
    FileNumber = FileNumber + 1
    if download(URLFromList, "test" & FileNumber & ".txt", false) then
        wscript.echo "download ok for " & URLFromList
    else
        wscript.echo "download did not work for " & URLFromList
    end if
Loop
objFile.Close
objFSO = Nothing
于 2013-02-04T16:24:58.820 回答