Jump to content

Repeat IE Function a number of times


 Share

Recommended Posts

well, i have this code that works perfectly as it should in the first time

ie page created >> all links in page opened >> select all >> copy >> paste in notepad >> save >> mouse click next page (within the same page so same address in address bar)

#include <IE.au3>
$oIE = _IECreate ("http://www.ldlp-dictionary.com/home/words/69")
$oLinks = _IELinkGetCollection ($oIE)
Local $i = 0
copySelected ()

Func copySelected ()
   $i = $i + 1
For $oLink In $oLinks
 If StringInStr($oLink.href, "www.ldlp-dictionary.com/dictionaries/word/")> 0 Then _IEAction($oLink, "click")
    _IELoadWait($oIE)
 Next
Sleep(1000)
Send("^a")
Sleep(1000)
Send("^c")
Sleep(1000)
WinActivate("[CLASS:Notepad]", "")
Sleep(1000)
Send("^v")
Sleep(1000)
Send("^s")
Sleep(1000)
MouseClick($MOUSE_CLICK_LEFT, 201, 469, 2)
_IELoadWait($oIE)
Sleep(1000)

if $i < 3 Then
   copySelected ()
EndIf
EndFunc

now the only problem that i need the function to be repeated for the existing page not create a new one so the function is not working properly after the first time

so i want the function to be repeated inside the current page over and over

how can i do it ?

Link to comment
Share on other sites

No worries, I actually had a play with your code and came up with the following but wasn't sure if that's what you wanted, currently it places the link text, the keyword and description into an array, you could write it to csv or text file afterwards.  It would take a while though to get through 1200 pages.

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

Global $aContent[1][3]
$oIE = _IECreate ("http://www.ldlp-dictionary.com/home/words/69")
$oLinks = _IELinkGetCollection ($oIE)
$oInnerContent = _IEGetObjById($oIE, "inner_content")
$oSpans = _IETagNameGetCollection($oIE, "span")
    For $oSpan In $oSpans
        If $oSpan.ClassName = "pagination" Then $iCount = Number(StringReplace($oSpan.InnerText, "  Page  of ", ""))
    Next
    copySelected()
    For $i = 2 To $iCount
        $oIE = _IECreate ("http://www.ldlp-dictionary.com/home/words/69/" & $i & "/")
        copySelected()
    Next

Func copySelected ()
    Local $sLink, $sKeyword, $sDesc
    $oInnerContent = _IEGetObjById($oIE, "inner_content")
    $oDivs = _IETagNameGetCollection($oInnerContent, "div")
    For $oDiv In $oDivs
        If $oDiv.ClassName = "titles dict_desc" Then
            ReDim $aContent[UBound($aContent) + 1][3]
            $oLinks = _IETagNameGetCollection($oDiv, "a")
            For $oLink In $oLinks
                If $oLink.ClassName = "dict_title" Then
                    _IEAction($oLink, "click")
                    _IELoadWait($oIE)
                    Sleep(1000)
                    $aContent[UBound($aContent) - 1][0] = $oLink.InnerText
                EndIf
            Next
            $oInnerDivs = _IETagNameGetCollection($oDiv, "div")
            For $oInnerDiv In $oInnerDivs
                If $oInnerDiv.id = "keywordContainer" Then $aContent[UBound($aContent) - 1][1] = $oInnerDiv.InnerText
                If $oInnerDiv.ClassName = "definitionListEntry" Then $aContent[UBound($aContent) - 1][2] = $oInnerDiv.InnerText
            Next
        EndIf
    Next
    $aContent[0][0] = UBound($aContent) - 1
    _ArrayDisplay($aContent)
EndFunc

 

Link to comment
Share on other sites

please don't keep opening new threads with the same issue.

but this looks like a better thing to do than call your copy function that repeatedly hits the _IEGetCollections

Edited by Earthshine

My resources are limited. You must ask the right questions

 

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...