重复使用多个网址的vbs脚本

时间:2017-09-02 12:22:24

标签: vbscript

我需要自动运行此脚本,但需要在urllist.txt文件中指定不同的URL。

Dim objWshShell,IE,searchStr

Set objWshShell = Wscript.CreateObject("Wscript.Shell")
Set IE = CreateObject("InternetExplorer.Application")

With IE
  .Visible = True
  .Navigate "url.com"

  Do While .Busy
    WScript.Sleep 100
  Loop

set objButtons = IE.document.getElementsByTagName("button")
for each objButton in objButtons
    strText = objButton.innerhtml

    if InStr(strText,"rtes") > 0 then
    'msgbox strText
objButton.click
        exit for
        end if
next
end with
ie.quit

urllist.txt内容:

url1.com url2.com ...

你能帮忙吗?

1 个答案:

答案 0 :(得分:0)

打开文本文件,使用 readline 方法逐行读取,并为每行运行代码。

代码:

Dim IE,searchStr, objFso, objFile, strFilePath
strFilePath = "store the file's path in this variable"   'store the path here
Set IE = CreateObject("InternetExplorer.Application")
IE.visible=True
Set objFso = createObject("Scripting.FileSystemObject")
Set objFile = objFso.OpenTextFile(strFilePath,1)
While Not objFile.AtEndOfStream
    IE.Navigate trim(objFile.Readline)
    Do While IE.Busy
        WScript.Sleep 100
    Loop
    set objButtons = IE.document.getElementsByTagName("button")
    for each objButton in objButtons
        strText = objButton.innerhtml
        if InStr(1,strText,"rtes") > 0 then
            'msgbox strText
             objButton.click
             exit for
        end if
    next
Wend
IE.Quit
objFile.Close
Set objFile = Nothing
Set objFso = Nothing
Set IE = Nothing