2017-09-02 127 views
0

我需要自动运行此脚本,但使用urllist.txt文件中指定的不同url。重复多个网址的vbs脚本

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

能否请你帮忙吗?

+0

逐行读取使用的文件系统对象的文本文件行。对于每一行,执行你粘贴的代码。 – Gurman

+0

谢谢。现在我可以从urllist.txt读取URL。 如何导航我的脚本到这些URL并让脚本完成这项工作? 我加入这个在VBScript中的顶部: 文件名= “urllist.txt中” 设置FSO =的CreateObject( “Scripting.FileSystemObject的”) 集F = fso.OpenTextFile(文件名) 做,直到f.AtEndOfStream WScript.Echo f.ReadLine Loop f。关闭 –

+0

刚刚发布在答案中。只需将您的url文件的路径存储在变量中并运行代码即可。 – Gurman

回答

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 
+0

几个网址运行完美,但过了一段时间后停止。如果关闭IE,800A01CE错误代码会附带VBScript运行时错误消息。 我需要在某个地方设置睡眠时间吗? –

+0

你能通过编辑你的问题在这里分享你的文本文件的URL吗?会尝试跑在我身边。 – Gurman

+0

我试图在facebook组中按按钮来设置每组中的警报。看起来,Facebook需要一些时间来启用下一个动作。我增加了睡眠到20000.现在它再次运作。 –