Reputation: 735
I'm trying to figure out how can I click a URL that matches a specific pattern. For example:
#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
Basically what I need to achieve is, if a $oLink in $oLinks contains $pattern - click on it. The above program, for some reason, does not work.
Any suggestions?
Thank you
Upvotes: 0
Views: 527
Reputation: 2151
Do you get your links with this piece of code?
#include <Array.au3>
#include <Inet.au3>
local $pattern = "/123/"
$source = _INetGetSource('https://www.nytimes.com/')
$links = StringRegExp($source, 'href="(http.*?)"', 3)
_ArrayDisplay($links)
Then you just need to adapt your For Next loop and use StringInStr on every links[$i]
Upvotes: 1
Reputation: 52878
I'm not sure if you can use StringInStr
on the object.
Try using:
StringInStr($oLink.href, $pattern)
instead.
Upvotes: 1