Jump to content

Need help using _IELinkGetCollection


Recommended Posts

Hi, been a long time since I've used auto it and forgot a lot of stuff. First of all what I'm trying to do here, is get a list of links found by _IELinkGetCollection , and filter them to only ones with a certain text, and then store a random one with the text I specify (theres always several of them).

I was able to get the list of all links, and log them to a txt file. How would I go about filtering them by a certain text they have in it so I can store my random variable?

EDIT:

Example, _IEGetLinkCollection gives this put put:

Test.com

Test1.com

Test2.com

Test.net

Test2.net

I'd like to be able to filter out the .coms and only log the .nets, so I can then select a random one and store it to a variable.

Edited by lolp1
Link to comment
Share on other sites

Update, Tried:

#include <IE.au3>
#include <file.au3>
$oIE = _IECreate("test.com")
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks
;MsgBox(0, "Link Info", $oLink.href)
if StringInStr($oLink.href, "test") = 1 Then
    _FileWriteLog(@ScriptDir & "\dump.txt",$oLink.href)
Next

Elseif 
Next

endif
First, get a grip on StringInStr(). It doesn't return 1, unless the search string begins exactly at character position 1. Try this to get a look at the links:
#include <IE.au3>
#include <file.au3>

$oIE = _IECreate("http://www.autoitscript.com")
$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
ConsoleWrite("Debug: " & $iNumLinks & " links found")
For $oLink In $oLinks
    If StringInStr($oLink.href, "test") And StringInStr($oLink.href, ".net") Then
        ConsoleWrite("Debug: Match!  " & $oLink.href & @LF)
    Else
        ConsoleWrite("Debug: No Match:  " & $oLink.href & @LF)
    EndIf
Next

This usage of StringInStr() works because it only returns 0 for no match, and any non-zero character position returned is treated as "True" in a boolean operation.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

First, get a grip on StringInStr(). It doesn't return 1, unless the search string begins exactly at character position 1. Try this to get a look at the links:

#include <IE.au3>
#include <file.au3>

$oIE = _IECreate("http://www.autoitscript.com")
$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
ConsoleWrite("Debug: " & $iNumLinks & " links found")
For $oLink In $oLinks
    If StringInStr($oLink.href, "test") And StringInStr($oLink.href, ".net") Then
        ConsoleWrite("Debug: Match!  " & $oLink.href & @LF)
    Else
        ConsoleWrite("Debug: No Match:  " & $oLink.href & @LF)
    EndIf
Next

This usage of StringInStr() works because it only returns 0 for no match, and any non-zero character position returned is treated as "True" in a boolean operation.

:)

Good explaing, works pefect, now I can work on storing my variable. First thing that comes to mind is using FileWriteLine FileReadLine to log them, as well as store a random link once it collects them to a variable, I'll post how it turns out or if I find a better way.
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...