【问题标题】:Repeating vbs script with multiple urls使用多个 url 重复 vbs 脚本
【发布时间】:2017-09-02 21:33:18
【问题描述】:

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

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 ...

你能帮忙吗?

【问题讨论】:

  • 使用文件系统对象逐行读取文本文件。对于每一行,执行您粘贴的代码。
  • 谢谢。现在我可以从 urllist.txt 中读取 url。如何将我的脚本导航到这些 url 并让脚本完成工作?我在 vbscript 的顶部添加了这个: filename = "urllist.txt" Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(filename) Do Until f.AtEndOfStream WScript.Echo f.ReadLine Loop f.关闭
  • 刚刚发布在答案中。只需将 url 文件的路径存储在变量中并运行代码即可。
  • 还要确保文本文件中的每一行都有一个 URL。

标签: vbscript


【解决方案1】:

打开文本文件,使用 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

【讨论】:

  • 一些 url 运行良好,但过了一会儿就停止了。如果我关闭 IE,800A01CE 错误代码带有 VBScript 运行时错误消息。我需要在某个地方设置睡眠时间吗?
  • 您能否通过编辑您的问题在此处分享您的文本文件的 URL?会试着站在我这边跑。
  • 我正在尝试在 facebook 群组中按下按钮以在每个群组中设置警报。看来,facebook 需要一些时间来启用下一个操作。我将睡眠增加到 20000。现在它又可以工作了。
猜你喜欢
  • 1970-01-01
  • 2014-11-04
  • 1970-01-01
  • 1970-01-01
  • 2015-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
相关资源
最近更新 更多