Jump to content
Sign in to follow this  
CemalSenturk

hi again I want to finalize my project :)

Recommended Posts

CemalSenturk

#include <IE.au3>

Global $goIE = 0
Global $gsURL = "http://www.car.gr/classifieds/tractors/edit/5934677/#details"
Global $gsPassword = "---"

_Login($goIE, $gsPassword, $gsURL)
If @error Then
    Exit @error + _IEQuit($goIE) - 1
 EndIf

; submit the form
_mySubmitSavePage($goIE)

Func _mySubmitSavePage(ByRef $oObj)
Exit @error + _IEQuit($goIE) - 1
    If Not IsObj($oObj) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $aoForm = _IEJS_GetObjByClassArray($oObj, "form-horizontal", "form")
    If Not IsArray($aoForm) Then
        Return SetError(2, 0, 0)
    EndIf

    Local $oForm = $aoForm[0] ; get the form from the array

    _IEFormSubmit($oForm)
    If @error Then
        Return SetError(3, 0, 0)
    EndIf

    ; wait for rendering to start
    Sleep(2000)

    ; wait for page to load
    _IELoadWait($oObj)
    If @error Then
        Return SetError(4, 0, 0)
    EndIf

    Return 1
EndFunc

Func _Login(ByRef $oObj, $sPassword, $sURL)

    If Not IsObj($oObj) Then
        $oObj = _IECreate($sURL)
        If Not IsObj($oObj) Then
            Return SetError(1, 0, 0)
        EndIf
        _IELoadWait($oObj)
    EndIf

    Local $aoForm = _IEJS_GetObjByClassArray($oObj, "form-horizontal", "form")
    If Not IsArray($aoForm) Then
        Return SetError(2, 0, 0)
    EndIf

    Local $oForm = $aoForm[0] ; get the form from the array

    Local $oPass = _IEGetObjByName($oForm, "password", 0); first instance only
    If Not IsObj($oPass) Then
        Return SetError(3, 0, 0)
    EndIf

    _IEFormElementSetValue($oPass, $gsPassword)

    ; login
    _IEFormSubmit($oForm)
    If @error Then
        Return SetError(4, 0, 0)
    EndIf

    ; wait for rendering to start
    Sleep(2000)

    ; wait for page to load
    _IELoadWait($oObj)
    If @error Then
        Return SetError(5, 0, 0)
    EndIf

    Return 1
EndFunc

Func _IEJS_GetObjByClassArray(ByRef $oObj, $sClass, $sTag = Default, $iIndex = -1)
    ; returns an array of objects

    If Not IsObj($oObj) Then
        Return SetError($_IESTATUS_InvalidDataType, 1, 0)
    EndIf

    $iIndex = (IsKeyword($iIndex) Or $iIndex < 0) ? -1 : $iIndex
    $sTag = (IsKeyword($sTag) Or Not StringLen($sTag)) ? "" : $sTag

    Local $oTags = (StringLen($sTag)) ? _IETagNameGetCollection($oObj, $sTag, $iIndex) : _
        _IETagNameAllGetCollection($oObj, $iIndex)
    Local $iExtended = @extended
    If Not IsObj($oTags) Then
        Return SetError($_IESTATUS_NoMatch, 2, 0)
    EndIf

    Local $aRet[$iExtended], $iCount
    If $iIndex = -1 Then
        For $oTag In $oTags
            If String($oTag.classname) = $sClass Then
                $aRet[$iCount] = $oTag
                $iCount += 1
            EndIf
        Next
    Else
        $aRet[$iCount] = $oTags.index($iIndex)
        If Not IsObj($aRet[$iCount]) Then
            Return SetError($_IESTATUS_InvalidValue, 3, 0)
        EndIf
        $iCount += 1
    EndIf

    If Not $iCount Then
        Return SetError($_IESTATUS_NoMatch, 4, 0)
    EndIf

    ReDim $aRet[$iCount]

    Return SetError($_IESTATUS_Success, 1, $aRet)
 EndFunc

_IEQuit($goIE)

Here is my (actualy not mine is SmOke_N's code) skalistir.au3 code. When I click this au3 script just logins to the page and nothing. But If I re-open it then finds the button and click it. All of the commands I use is inside run.au3 (here):

ConsoleWrite(@ScriptDir & @CRLF)
_RunAU3("skalistir.au3")
_RunAU3("skalistir.au3")
_RunAU3("spastrakuc.au3")
_RunAU3("spastrakuc.au3")
_RunAU3("spastrabuy.au3")
_RunAU3("spastrabuy.au3")
_RunAU3("spastraele.au3")
_RunAU3("spastraele.au3")

Func _RunAU3($sFilePath, $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)
    ConsoleWrite(FileExists($sFilePath) & @TAB & '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"' & @CRLF)
    $iReturn = Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"', $sWorkingDir, $iShowFlag, $iOptFlag)
    Sleep(3500)
    Return $iReturn
 EndFunc

But after the job finished 4 of the Internet Explorer page stands and I want to close them automatically. Any Ideas how to ?

Edited by CemalSenturk

Share this post


Link to post
Share on other sites
CemalSenturk

I know you are professionals and you are hating members like me but I don't know how to exactly use that. Can you please help me to where to put that code? Thanks a lot :)

Share this post


Link to post
Share on other sites
CemalSenturk

Yes I see but I can't figure out where to put that code :geek:

Edited by CemalSenturk

Share this post


Link to post
Share on other sites
SmOke_N

Wow, that code is nearly 100% me! lmao...

Put _IEQuit($goIE) after _mySubmitSavePage($goIE)

Edit:

And change this:

ConsoleWrite(@ScriptDir & @CRLF)
_RunAU3("skalistir.au3")
_RunAU3("skalistir.au3")
_RunAU3("spastrakuc.au3")
_RunAU3("spastrakuc.au3")
_RunAU3("spastrabuy.au3")
_RunAU3("spastrabuy.au3")
_RunAU3("spastraele.au3")
_RunAU3("spastraele.au3")

Func _RunAU3($sFilePath, $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)
    ConsoleWrite(FileExists($sFilePath) & @TAB & '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"' & @CRLF)
    $iReturn = Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"', $sWorkingDir, $iShowFlag, $iOptFlag)
    Sleep(3500)
    Return $iReturn
 EndFunc

To this:

ProcessWaitClose(_RunAU3("skalistir.au3"))
ProcessWaitClose(_RunAU3("skalistir.au3"))
ProcessWaitClose(_RunAU3("spastrakuc.au3"))
ProcessWaitClose(_RunAU3("spastrakuc.au3"))
ProcessWaitClose(_RunAU3("spastrabuy.au3"))
ProcessWaitClose(_RunAU3("spastrabuy.au3"))
ProcessWaitClose(_RunAU3("spastraele.au3"))
ProcessWaitClose(_RunAU3("spastraele.au3"))

Func _RunAU3($sFilePath, $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)
    Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"', $sWorkingDir, $iShowFlag, $iOptFlag)
EndFunc
Edited by SmOke_N
  • Like 1

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
CemalSenturk

Oh man you are genious! Thank you but here is a problem.

_Login($goIE, $gsPassword, $gsURL)
If @error Then
    Exit @error + _IEQuit($goIE) - 1
EndIf

; submit the form
_mySubmitSavePage($goIE)
_IEQuit($goIE)

Func _mySubmitSavePage(ByRef $oObj)

Here is the code I put it at 14th line but as I said when I first run the code skalistir.au3. After the line 13rd script pauses. At second try, creates a new page but do not asks for password or username, directly finds the button and clicks on it. This is why I use two _RunAU3 instead of one :) Can we fix it?

I tried your last code and stuck at first line of run.au3 script :) Can't create a new page and waits for proccess to close. My idea is Run all of them wıth 3.5 sec delay and after it force to close iexplore.exe. Is it possible ? How? Thanks..

Share this post


Link to post
Share on other sites
SmOke_N

Turn your cache off (or Clear cache upon exit within your Internet Explorer -> Tools -> Internet Options -> Advanced Tab -> Security: Empty Temporary Internet Files folder when browser is closed -> Click OK).

Your setup is a hot mess.  I would just use one script to do it all.

#include <IE.au3>

Global $goIE = 0
Global $gaURLs[4]
$gaURLs[0] = "http://www.car.gr/classifieds/tractors/edit/5934677/#details"
$gaURLs[1] = "URL2" ; <--- Put your other URLs in these spots
$gaURLs[2] = "URL3"
$gaURLs[3] = "URL4"

Global $gsPassword = "---"

For $i = 0 To UBound($gaURLs) - 1
    _Login($goIE, $gsPassword, $gaURLs[$i])
    If @error Then
        Exit @error + _IEQuit($goIE) - 1
    EndIf

    ; submit the form
    _mySubmitSavePage($goIE)
Next
_IEQuit($goIE)

Func _mySubmitSavePage(ByRef $oObj)
    
    If Not IsObj($oObj) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $aoForm = _IEJS_GetObjByClassArray($oObj, "form-horizontal", "form")
    If Not IsArray($aoForm) Then
        Return SetError(2, 0, 0)
    EndIf

    Local $oForm = $aoForm[0] ; get the form from the array

    _IEFormSubmit($oForm)
    If @error Then
        Return SetError(3, 0, 0)
    EndIf

    ; wait for rendering to start
    Sleep(2000)

    ; wait for page to load
    _IELoadWait($oObj)
    If @error Then
        Return SetError(4, 0, 0)
    EndIf

    Return 1
EndFunc

Func _Login(ByRef $oObj, $sPassword, $sURL)

    If Not IsObj($oObj) Then
        $oObj = _IECreate()
        If Not IsObj($oObj) Then
            Return SetError(1, 0, 0)
        EndIf
        _IELoadWait($oObj)
    EndIf
    
    _IENavigate($oObj, $sURL)
    _IELoadWait($oObj)
    
    Local $aoForm = _IEJS_GetObjByClassArray($oObj, "form-horizontal", "form")
    If Not IsArray($aoForm) Then
        Return SetError(2, 0, 0)
    EndIf

    Local $oForm = $aoForm[0] ; get the form from the array

    Local $oPass = _IEGetObjByName($oForm, "password", 0); first instance only
    If Not IsObj($oPass) Then
        Return SetError(3, 0, 0)
    EndIf

    _IEFormElementSetValue($oPass, $gsPassword)

    ; login
    _IEFormSubmit($oForm)
    If @error Then
        Return SetError(4, 0, 0)
    EndIf

    ; wait for rendering to start
    Sleep(2000)

    ; wait for page to load
    _IELoadWait($oObj)
    If @error Then
        Return SetError(5, 0, 0)
    EndIf

    Return 1
EndFunc

Func _IEJS_GetObjByClassArray(ByRef $oObj, $sClass, $sTag = Default, $iIndex = -1)
    ; returns an array of objects

    If Not IsObj($oObj) Then
        Return SetError($_IESTATUS_InvalidDataType, 1, 0)
    EndIf

    $iIndex = (IsKeyword($iIndex) Or $iIndex < 0) ? -1 : $iIndex
    $sTag = (IsKeyword($sTag) Or Not StringLen($sTag)) ? "" : $sTag

    Local $oTags = (StringLen($sTag)) ? _IETagNameGetCollection($oObj, $sTag, $iIndex) : _
        _IETagNameAllGetCollection($oObj, $iIndex)
    Local $iExtended = @extended
    If Not IsObj($oTags) Then
        Return SetError($_IESTATUS_NoMatch, 2, 0)
    EndIf

    Local $aRet[$iExtended], $iCount
    If $iIndex = -1 Then
        For $oTag In $oTags
            If String($oTag.classname) = $sClass Then
                $aRet[$iCount] = $oTag
                $iCount += 1
            EndIf
        Next
    Else
        $aRet[$iCount] = $oTags.index($iIndex)
        If Not IsObj($aRet[$iCount]) Then
            Return SetError($_IESTATUS_InvalidValue, 3, 0)
        EndIf
        $iCount += 1
    EndIf

    If Not $iCount Then
        Return SetError($_IESTATUS_NoMatch, 4, 0)
    EndIf

    ReDim $aRet[$iCount]

    Return SetError($_IESTATUS_Success, 1, $aRet)
 EndFunc

.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
CemalSenturk

I turned my cache off but nothing changed. I will use your old code. Closing 4 browsers won't kill me :) Thank you again.

Share this post


Link to post
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
Sign in to follow this  

×