Jump to content

_IELinkClickbytext and loop through an array


Recommended Posts

Hi,

I'm trying to extend the example in the online documentation of _IeLinkClickbyText. Instead of using just one predefined String, I want to use an array which i have read from an excel sheet. The script should now loop through all the links found on the url and check if the link contains a substring matching with one of my fields in the array. In the case of success the script should send me the source code of the following page via _InetGetSource. Unfortunately it doesn't work very well.

This is my actual code:

#include <IE.au3>
#include <array.au3>
#include <excel.au3>
#include <inet.au3>

$o_database = _ExcelBookOpen("Path to Excel Sheet")
$o_cardname_array = _ExcelReadArray ($o_database, 2, 2, 50, 0 , 0)
$oIE = _IECreate("PutYourUrlInHere")
$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")

For $l = 0 to UBound($o_cardname_array) -1
    For $oLink In $oLinks
        $sLinkText = _IEPropertyGet($oLink, "innerText")
        If StringInStr($sLinkText, $o_cardname_array[$l]) Then
        _INetGetSource($oLink.href)
            ExitLoop
        EndIf
    Next
Next
_ExcelBookClose($o_database,1)
_IEAction($oIE,"quit")

Hopefully anyone has an idea to solve this problem. Any help would be appreciated.

Link to comment
Share on other sites

You're not storing the source anywhere in your code, you're just calling _INetGetSource() and nothing. You can use FileWrite() or something to write the source to a file, or at least store it. Another problem is that you'll usually see something like <a href="/Wiki">Wiki</a> which is a relative path so you should take it into consideration.

Link to comment
Share on other sites

Oh sorry just a mistake in my first post. I forgot a variable there. The correct version is:

#include <IE.au3>
#include <array.au3>
#include <excel.au3>
#include <inet.au3>

$o_database = _ExcelBookOpen("Path to Excel Sheet")
$o_cardname_array = _ExcelReadArray ($o_database, 2, 2, 50, 0 , 0)
$oIE = _IECreate("PutYourUrlInHere")
$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")

For $l = 0 to UBound($o_cardname_array) -1
    For $oLink In $oLinks
        $sLinkText = _IEPropertyGet($oLink, "innerText")
        If StringInStr($sLinkText, $o_cardname_array[$l]) Then
        $o_source = _INetGetSource($oLink.href)
        [... doing some things with the source code ...]
            ExitLoop
        EndIf
    Next
Next
_ExcelBookClose($o_database,1)
_IEAction($oIE,"quit")

Maybe I need to clarify my problem. The script never enters the if clause. Probably the String in String is not found, although it should be. If I'm using "xxxx" (for example "wallpaper" like in the online documentation) instead of $o_cardname_array[$l] it works. But if it's in the array it doesn't.

Link to comment
Share on other sites

Do some debugging?

Like:

#include <IE.au3>
#include <array.au3>
#include <excel.au3>
#include <inet.au3>

$o_database = _ExcelBookOpen("Path to Excel Sheet")
$o_cardname_array = _ExcelReadArray($o_database, 2, 2, 50, 0, 0)
_ExcelBookClose($o_database, 1)

_ArrayDisplay($o_cardname_array) ; Show the contents of your Excel Array to confirm that you got anything from it

$oIE = _IECreate("PutYourUrlInHere")
$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")

For $l = 0 To UBound($o_cardname_array) - 1
    For $oLink In $oLinks
        $sLinkText = _IEPropertyGet($oLink, "innerText")
        MsgBox(0, "", "Array Text: " & $o_cardname_array[$l] & @CRLF & "Link Text: " & $sLinkText)
        If StringInStr($sLinkText, $o_cardname_array[$l]) Then
            MsgBox (0, "Matched!", "Array Text: " & $o_cardname_array[$l] & @CRLF & "Link Text: " & $sLinkText & @CRLF "Matched!")
            $o_source = _INetGetSource($oLink.href)
;~         [... doing some things with the source code ...]
            ExitLoop
        EndIf
    Next
Next
_ExcelBookClose($o_database, 1)
_IEAction($oIE, "quit")
Edited by exodius
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...