user2518751
user2518751

Reputation: 735

Autoit - searching for a URL in a web page and click on it

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

Answers (2)

Xenobiologist
Xenobiologist

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

Daniel Haley
Daniel Haley

Reputation: 52878

I'm not sure if you can use StringInStr on the object.

Try using:

StringInStr($oLink.href, $pattern)

instead.

Upvotes: 1

Related Questions