Jump to content

Click Link By Index , IE UDF


Recommended Posts

; *******************************************************
; Example 1 - Open browser with basic example, get link collection,
;               loop through items and display the associated link URL references
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
$oLinks = _IELinkGetCollection ($oIE, -1)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks
    MsgBox(0, "Link Info", $oLink.href)
Next

-------------

Would it be possible to get an example showing the index Number with the URLs, and perhaps print them to a file?

Link to comment
Share on other sites

Would it be possible to get an example showing the index Number with the URLs, and perhaps print them to a file?

Simple way I thought to do this, Not sure if it is 100% correct.. And I will need to do a tad more research to save to a file again.

; *******************************************************
; Example 1 - Open browser with basic example, get link collection,
;               loop through items and display the associated link URL references
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
$oLinks = _IELinkGetCollection ($oIE, -1)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
$oIndexNumber = -1
For $oLink In $oLinks
    $oIndexNumber = $oIndexNumber + 1
    MsgBox(0, "Link Info", $oLink.href & " " & $oIndexNumber)
Next
Link to comment
Share on other sites

Yet again,

Modified Example.

; *******************************************************
; Example 1 - Open browser with basic example, get link collection,
;               loop through items and display the associated link URL references
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
$oLinks = _IELinkGetCollection ($oIE, -1)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
$oIndexNumber = -1
$file = FileOpen("LinkIndexs.txt", 1)
For $oLink In $oLinks
    If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
    EndIf
$oIndexNumber = $oIndexNumber + 1
;MsgBox(0, "Link Info", $oLink.href & " " & $oIndexNumber)
    FileWrite($file, $oLink.href & " " & $oIndexNumber & @CRLF)
Next
FileClose($file)
Edited by jacob_1998_1999
Link to comment
Share on other sites

I have gotten everything that I wanted from LinkClickByIndex -- Other than the fact that it Does NOT work (to my knowledge) When the window is brought up from the _IEcreate("http://www.Google.com", 0,0) method. Am I going about this wrong.. Or am I trying to write my project to do something that is means are not capable for yet?

Link to comment
Share on other sites

Perhaps found my problem..

$oButton = _IEFormElementGetObjByName($oForm, "submit")

$oButton.focus()

Send("{Enter}")

This does not go through in the "hidden" state.

HTML of the Form I am trying to get through.

    <tr><td>Username:</td><td><input name=username></td></tr>
    <tr><td>Password:</td><td><input type=password name=password></td></tr>
    <tr><td></td><td><input name=submit class=submit type=submit value='log in'</td></tr>

Can anyone think of another way to get into it?

Link to comment
Share on other sites

Use _IEFormSetElementValue() and _IEFormSubmit() check IE.au3 ...

Make $form,$username,$password obj references to the form and the inputs, respectively.

_IEFormSetElementValue($username,'username')

_IEFormSetElementValue($password,'password')

_IEFormSubmit($form)

EDIT: To hit the submit button, try _IEClickLinkByText() I think that's what it's called...

Sparkes.

Edited by Andrew Sparkes

---Sparkes.

Link to comment
Share on other sites

I Do need to use a Regex for another part in this script.. But sadly I know nothing about regex at all.. A example of why I would need it is as follows:

<a href="/attack.php?UID=7357&tkid=942bb7fbd033a09be0e48ead211a2f29">Attack</a>

I would like to search the entire page for all "/attack.php?UID=" yet.. Exclude 2 specific ones.. And Simulate a click on links that are avaliable that are not the 2 I specify. Is that confusing enough? :D

Sorry for going off topic.

EDIT:

of <a href="/attack.php?UID=7357&tkid=942bb7fbd033a09be0e48ead211a2f29">Attack</a> I only need to actually search for "attack.php?UID=###&"

Edited by jacob_1998_1999
Link to comment
Share on other sites

  • Moderators

I Do need to use a Regex for another part in this script.. But sadly I know nothing about regex at all.. A example of why I would need it is as follows:

<a href="/attack.php?UID=7357&tkid=942bb7fbd033a09be0e48ead211a2f29">Attack</a>

I would like to search the entire page for all "/attack.php?UID=" yet.. Exclude 2 specific ones.. And Simulate a click on links that are avaliable that are not the 2 I specify. Is that confusing enough? :D

Sorry for going off topic.

EDIT:

of <a href="/attack.php?UID=7357&tkid=942bb7fbd033a09be0e48ead211a2f29">Attack</a> I only need to actually search for "attack.php?UID=###&"

This should get you started:

Requirements:

Latest Beta

#include <IE.au3>
#include <Array.au3>

Dim _
        $i = 0, _
        $aLinks[1], _
        $sExclude1 = "whatever1", _
        $sExclude2 = "whatever2", _
        $sInclude = "attack.php?UID=", _
        $sURL = "www.your-webpage.com"

$oIE = _IECreate ($sURL)
; Get a collection all all links
$oLinks = _IELinkGetCollection ($oIE)
; Loop through all links
For $oLink In $oLinks
    ; Get the href value for the current link
    $sHREF = $oLink.href
    ; Check that it matches the type of links we are looking for
    If StringInStr($sHREF, $sInclude) Then
        ; Check that it do not include our excluded strings
        If Not StringInStr($sHREF, $sExclude1) And StringInStr($sHREF, $sExclude2) Then
            ReDim $aLinks[$i + 1]
            ; Build an array of all links that passed our test
            $aLinks[$i] = $sHREF
            $i += 1
        EndIf
    EndIf
Next

_ArrayDisplay($aLinks, "Matching Links")
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...