2017-08-16 77 views
0

我想弄清楚如何点击匹配特定模式的网址。 例如:Autoit - 在网页中搜索网址并点击它

#include <IE.au3> 
#include <MsgBoxConstants.au3> 

local $pattern = "/123/" 
Local $oIE = _IECreate("www.example.com",0,1,1,1) 
Local $oLinks = _IELinkGetCollection($oIE) 

For $oLink In $oLinks 

    If StringInStr($oLink, $pattern) Then 
     _IEAction($oLink, "click") 
     sleep(700) 
     _IEQuit($oIE) 
     ExitLoop 
    EndIf 
Next 

基本上我需要实现的是, 如果$ OLINK在$ oLinks包含$模式 - 点击它。 上述程序出于某种原因不起作用。

有什么建议吗?

谢谢

+2

不知道,如果你可以用'StringInStr'的对象。尝试使用'StringInStr($ oLink.href,$ pattern)'代替。 –

+0

它工作!非常感谢 :) – user2518751

回答

1

我不知道,如果你可以在对象上使用StringInStr

尝试使用:

StringInStr($oLink.href, $pattern) 

代替。

1

你是否使用这段代码获得了链接?

#include <Array.au3> 
#include <Inet.au3> 
local $pattern = "/123/" 
$source = _INetGetSource('https://www.nytimes.com/') 
$links = StringRegExp($source, 'href="(http.*?)"', 3) 
_ArrayDisplay($links) 

然后你只需要去适应你的下一个循环,并使用StringInStr上的各个环节[$ i]