Jump to content

Trapped script


Recommended Posts

Hi everyone..

I just started the other day with AutoIt, becouse I needed a script for my work.

Have to say that I own some basic programming skills, so I'm not a pro. Anyway.

It's a simple task what my script should do, as follows:

- open in browser (e.g. Firefox) a page with info

- should autoclick on "Details", get some info from the new page

- write the info in a file

- go back to the original (eventually next) page and start all over.

All the help I've got through this forum (and some Google) made possible to make it.

The script works well, until a certain point. It stops after exaclty 45 cycles every time,

no mather what I change. I thought it could be the clipboard, but it's not.

I suspected the While..Wend loop, and it's not. Hoping that someone could find where I was wrong,

here is the code (I tried to comment it well, maybe someone else could get some use of it,

like I did from other posts):

;----------------------------------------------------------------- define variables and dependencies
#include <Array.au3> ;include for working with arrays
Global $Paused ;set a global variable
HotKeySet("{PAUSE}", "TogglePause") ;set the Pause/Break key to pause the program
HotKeySet("{ESC}", "Terminate") ;set the ESC key to exit from program
dim $array[1] ;clipboard array
dim $outarray[1] ;storage array
$pos = 0
$errorcatch = ""
$Accession = ""
$Modality = ""
$StudyDesc = ""
$PatientName = ""
$PatientID = ""
$PatientDOB = ""
$UseTitle = "Transport rutier international"
$UseTitle1 = "Catalog Transport"
$UseTitle2 = "Euload - Bursa"
$p1 = "http://catalog.euload.com/index.php?page=" ;page number goes here
$p2 = "&colsort=&colsortord=&showAll=false&srch_company=&srch_city="
$p3 = "&srch_cat=---&srch_country=ro&srch_region=0&srch_word=transport+rutier+international"
;----------------------------------------------------------------- settings
Opt("WinTitleMatchMode", 2) ;setting the window name search mode (so it contains the words we need)
;----------------------------------------------------------------- main
WinActivate($UseTitle2) ;wait for being active the right window with the start page
While 1 ;setting up an infinite loop
for $x=1 to 435 ;there are 435 pages what we need
    $p4 = $p1 & $x & $p2 & $p3 ;define the page where go to
    ClipPut($p4) ;put that page in clipboard
    MouseClick("left",225,60,1,10) ;click at the beginnin of url bar
    Send("+{END}") ;select whatever is there
    Send("{DEL}") ;delete it
    send("^v") ;paste the page url
    send("{ENTER}") ;guess what :)
    ClipPut("") ; clear the clipboard
    Sleep(3000) ;wait for loading the page

        MouseClick(1,700,10) ;click to an unused space on the page
        Send("{PGUP 4}") ;going to the top of the page

        MouseClick("left",950,610,1,0) ; click on the first result's details
        WinWaitActive($UseTitle) ;wait to be active the right window
        Sleep(2000) ;wait for loading the page
        Call("SaveSpore") ;calling the write file routine
        WinWaitActive($UseTitle1) ;waiting for being active the search result page)

        MouseClick("left",950,650,1,0) ; click on the second result's details
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,690,1,0) ;click on the third result's details
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick(1,700,10) ;click to an unused space on the page
        MouseWheel("down",5) ;scrolling down on the search result page

        MouseClick("left",950,150,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,190,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,230,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,270,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,310,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,340,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,380,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,420,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,460,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,500,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,540,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,580,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,610,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,650,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,690,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick(1,700,10) ;click to an unused space on the page
        MouseWheel("down",2) ;scrolling down on the search result page

        MouseClick("left",950,500,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

        MouseClick("left",950,540,1,0) ;click on the next detail
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)

                ;the mouse click coords I've could put in a For...Next loop since they are very certain, 
                ;I tried it, but for some strange reason, the STEP 40 argument didn't worked,
                ;wich means that it was shrinking every cycle, so I abbandoned the idea. 
Next ;going to the next page
WEnd ;end the infinite loop

;----------------------------------------------------------------- declare functions
Func SaveSpore() ;function to copy the page to clipboard and write to the file the info obtained
    Send("^a") ;select text
    Send("^c") ;copy it to clipboard
    Sleep(250)
    $Dump = ClipGet() ;store the dump from clipboard into variable.
    $file = FileOpen("test.csv", 1) ;opening the file for input
    $array =StringSplit(StringStripCR($Dump), @LF) ;split data into single line arrays to parse.
    If Not @error Then

        $pos = _ArraySearch($array, "Nume Companie:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $StudyDate = StringTrimLeft($array[$pos], 16)
        _ArrayAdd($outarray, $StudyDate) ;put the clipboard array in normal array
        FileWrite($file, $StudyDate & ";") ;write into the file the information obtained (the array)
        EndSelect

        $pos = _ArraySearch($array, "Adresa:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $Accession = StringTrimLeft($array[$pos], 9)
        _ArrayAdd($outarray, $Accession)
        FileWrite($file, $Accession & ";")
        EndSelect

        $pos = _ArraySearch($array, "Oras:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $Modality = StringTrimLeft($array[$pos], 7)
        _ArrayAdd($outarray, $Modality)
        FileWrite($file, $Modality & ";")
        EndSelect

        $pos = _ArraySearch($array, "Judet:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $StudyDesc = StringTrimLeft($array[$pos], 8)
        _ArrayAdd($outarray, $StudyDesc)
        FileWrite($file, $StudyDesc & ";")
        EndSelect

        $pos = _ArraySearch($array, "Telefon:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $StudyDate = StringTrimLeft($array[$pos], 10)
        _ArrayAdd($outarray, $StudyDate)
        FileWrite($file, $StudyDate & ";")
        EndSelect

        $pos = _ArraySearch($array, "Fax:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $PatientID = StringTrimLeft($array[$pos], 6)
        _ArrayAdd($outarray, $PatientID)
        FileWrite($file, $PatientID & ";")
        EndSelect

        $pos = _ArraySearch($array, "Pagina WEB:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $PatientDOB = StringTrimLeft($array[$pos], 13)
        _ArrayAdd($outarray, $PatientDOB)
        FileWrite($file, $PatientDOB & ";")
        EndSelect

        $pos = _ArraySearch($array, "Limbi de contact:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $PatientDOB = StringTrimLeft($array[$pos], 19)
        _ArrayAdd($outarray, $PatientDOB)
        FileWrite($file, $PatientDOB & ";")
        EndSelect
        ;EndIf

        $pos = _ArraySearch($array, "Domeniu de activitate:", 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $PatientDOB = StringTrimLeft($array[$pos], 24)
        _ArrayAdd($outarray, $PatientDOB)
        FileWrite($file, $PatientDOB & ";" & @CRLF)
        EndSelect
    ClipPut("")
    EndIf
    ;_ArrayDisplay($outArray, "Array") ;display the array, holy cow, it works.
    Sleep(250)
    Send("^{F4}") ;close the detail page
    Sleep(250)
    FileClose($file) ;close the file (save it)
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Prgoramma in pausa"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    FileClose($file)
    ClipPut("")
    Exit 0
EndFunc

Sorry for the long post, and sorry for my english, it's not the best..

In the hope that someone could help,

Best wishes,

Andrew.

Edited by andrew222

Everybody starts from somewhere..

Link to comment
Share on other sites

You may want to look at using IE.au3 or FF.au3 to hook into the web page. It would make your script more stable. Second, I would setup a function for the following and call it:

MouseClick("left",950,650,1,0) ; click on the second result's details         
WinWaitActive($UseTitle)         
Sleep(2000)         
Call("SaveSpore")         
WinWaitActive($UseTitle1)

It is good practice whenever you repeat something more than once to create a function. In your case make a function and create a For/Next loop would work best here. I see you note saying you had an issue when you attempted it, but using the IE.au3 or FF.au3 would allow you to use a different method to click on the control besides using a mouse click. Hope this helps.

Link to comment
Share on other sites

You may want to look at using IE.au3 or FF.au3 to hook into the web page. It would make your script more stable. Second, I would setup a function for the following and call it:

MouseClick("left",950,650,1,0) ; click on the second result's details         
WinWaitActive($UseTitle)         
Sleep(2000)         
Call("SaveSpore")         
WinWaitActive($UseTitle1)

It is good practice whenever you repeat something more than once to create a function. In your case make a function and create a For/Next loop would work best here. I see you note saying you had an issue when you attempted it, but using the IE.au3 or FF.au3 would allow you to use a different method to click on the control besides using a mouse click. Hope this helps.

Thank you for the suggestions, I will take a look at those, even if, like I said, I'm not a pro, so at some point it looks to me "chinese".. :mellow: No offense.. I am in a kind of hurry with that script, that's why I choosed this forum, and not trying to debug it myself (anyway, for that manner I need much more knowledge, wich means time, wich I don't have pretty much..)

But thank you once again..

Best regards,

Andrew.

Everybody starts from somewhere..

Link to comment
Share on other sites

try cutting it down like this.

;----------------------------------------------------------------- define variables and dependencies
#include <Array.au3> ;include for working with arrays
Global $Paused ;set a global variable
HotKeySet("{PAUSE}", "TogglePause") ;set the Pause/Break key to pause the program
HotKeySet("{ESC}", "Terminate") ;set the ESC key to exit from program
dim $array[1] ;clipboard array
dim $outarray[1] ;storage array
$pos = 0
$errorcatch = ""
$Accession = ""
$Modality = ""
$StudyDesc = ""
$PatientName = ""
$PatientID = ""
$PatientDOB = ""
$UseTitle = "Transport rutier international"
$UseTitle1 = "Catalog Transport"
$UseTitle2 = "Euload - Bursa"
$p1 = "http://catalog.euload.com/index.php?page=" ;page number goes here
$p2 = "&colsort=&colsortord=&showAll=false&srch_company=&srch_city="
$p3 = "&srch_cat=---&srch_country=ro&srch_region=0&srch_word=transport+rutier+international"
;----------------------------------------------------------------- settings
Opt("WinTitleMatchMode", 2) ;setting the window name search mode (so it contains the words we need)
;----------------------------------------------------------------- main
WinActivate($UseTitle2) ;wait for being active the right window with the start page
While 1 ;setting up an infinite loop
for $x=1 to 435 ;there are 435 pages what we need
    $p4 = $p1 & $x & $p2 & $p3 ;define the page where go to
    ClipPut($p4) ;put that page in clipboard
    
    MouseClick("left",225,60,1,10) ;click at the beginnin of url bar
    Send("+{END}") ;select whatever is there
    Send("{DEL}") ;delete it
    send("^v") ;paste the page url
    send("{ENTER}") ;guess what :)
    ClipPut("") ; clear the clipboard
    Sleep(3000) ;wait for loading the page

        MouseClick(1,700,10) 
        Send("{PGUP 4}")

$pinky = 610
    for $p = 1 to 3 step 1
        MouseClick("left",950,$pinky,1,0) 
        WinWaitActive($UseTitle) 
        Sleep(2000) 
        Call("SaveSpore") 
        WinWaitActive($UseTitle1) 
        $pinky = $pinky + 40
    Next
        MouseClick(1,700,10) 
        MouseWheel("down",5) 
$linky = 150
    for $l = 1 to 15 step 1
        MouseClick("left",950,$linky,1,0)
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)
        $linky = $linky + 40
    Next
        MouseClick(1,700,10) 
        MouseWheel("down",2) 
$minky = 500
    for $m = 1 to 2 step 1
        MouseClick("left",950,$minky,1,0)
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)
        $minky = $minky + 40
    Next

Next 
WEnd 

;----------------------------------------------------------------- declare functions
Func SaveSpore() ;function to copy the page to clipboard and write to the file the info obtained
    Send("^a") ;select text
    Send("^c") ;copy it to clipboard
    Sleep(250)
    $Dump = ClipGet() ;store the dump from clipboard into variable.
    $file = FileOpen("test.csv", 1) ;opening the file for input
    $array =StringSplit(StringStripCR($Dump), @LF) ;split data into single line arrays to parse.
    If Not @error Then

    Local $Nombre[10]
    $Nombre[0] = "Nume Companie:"
    $Nombre[1] = "Adresa:"
    $Nombre[2] = "Oras:"
    $Nombre[3] = "Judet:"
    $Nombre[4] = "Telefon:"
    $Nombre[5] = "Fax:"
    $Nombre[7] = "Pagina WEB:"
    $Nombre[8] = "Limbi de contact:"
    $Nombre[9] = "Domeniu de activitate:"

for $q = 0 to 9
        $pos = _ArraySearch($array, $Nombre[$q], 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2)
        _ArrayAdd($outarray, $ReadOut) 
        FileWrite($file, $ReadOut & ";") 
        EndSelect
Next
    ClipPut("")
    EndIf

    Sleep(250)
    Send("^{F4}") ;close the detail page
    Sleep(250)
    FileClose($file) ;close the file (save it)
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Prgoramma in pausa"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    FileClose($file)
    ClipPut("")
    Exit 0
EndFunc
[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

Hi lordicast

It is very much appreciated the helping hand you are giving, and sorry for the late reply.

Your version is much more clear, much easyer to understand it. :mellow:

But I have to mention 2 things on it.

$ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2)

gaved me parsing error, wich I easily eliminated with

$long = StringLen($Nombre[$q]+2)
        $ReadOut = StringTrimLeft($array[$pos], $long)

So now it should be ok. BUT!

I don't know why, the For...Next cycle, so $linky, doesn't click at the right place.

Already tried before to implement such a loop, and neither your, nor mine doesn't work as expected. Don't ask me why.

Apart from that, there was some error on the page I accessed, that's why it stopped always at the same place.

Once continued with the next value, it continued withouth any problem.

Well, the only problem remains with the mouseclick coords, wich in "single mode" does the job, and in a loop doesn't.

Thank you very very much,

Andrew.

Everybody starts from somewhere..

Link to comment
Share on other sites

Hi andrew222, I'm not sure about your mouse coordinate issue. I guess it will be something to do with the maths. Also: it's difficult to tell without seeing the webpage. However the line below was just missing a closing bracket. I thought I ought to mention it.

$ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2))
Link to comment
Share on other sites

Hi andrew222, I'm not sure about your mouse coordinate issue. I guess it will be something to do with the maths. Also: it's difficult to tell without seeing the webpage. However the line below was just missing a closing bracket. I thought I ought to mention it.

$ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2))

Hello to you too, czardas,

Thank you for the correction, it was a minor thing, anyway.

A sample page of what I meant would be:

http://catalog.euload.com/index.php?page=1&colsort=&colsortord=&showAll=false&srch_company=&srch_city=&srch_cat=---&srch_country=ro&srch_region=0&srch_word=transport+rutier+international

I think that the mouse coordinates issue is not a math problem, since MouseClick at 150, then 190, then 230, then 270, should be exactly For $x=150 to 270 step 40, wich matematically IS true, at the mouse coords not anymore.

So, I have no clue about what's happening.

Best regard,

Andrew.

Everybody starts from somewhere..

Link to comment
Share on other sites

I don't know why, the For...Next cycle, so $linky, doesn't click at the right place.

Do $pinky and $minky click at the right place, or do they also have the same problem?

The mouse moves down by increments of 40. That seems to be working fine for me. Perhaps you can describe in more detail what you expect to happen, and what is going wrong. You can also test the position of the mouse using MouseGetPos, though it might not give you any new information. I would also look into the suggestions made by Volly.

Edited by czardas
Link to comment
Share on other sites

Do $pinky and $minky click at the right place, or do they also have the same problem?

The mouse moves down by increments of 40. That seems to be working fine for me. Perhaps you can describe in more detail what you expect to happen, and what is going wrong. You can also test the position of the mouse using MouseGetPos, though it might not give you any new information. I would also look into the suggestions made by Volly.

Thank you, too for the time spent with my problem. I will give you more details on the coord problem only tonight, because now I have to do other things. Meantime thank you very very much.

Everybody starts from somewhere..

Link to comment
Share on other sites

Thank you, too for the time spent with my problem. I will give you more details on the coord problem only tonight, because now I have to do other things. Meantime thank you very very much.

No problem. I'm sure you'll figure it out. I'm perhaps not the best person to ask about functions with the mouse, as I don't use them very much.
Link to comment
Share on other sites

Hi lordicast

It is very much appreciated the helping hand you are giving, and sorry for the late reply.

Your version is much more clear, much easyer to understand it. :mellow:

But I have to mention 2 things on it.

$ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2)

gaved me parsing error, wich I easily eliminated with

$long = StringLen($Nombre[$q]+2)
        $ReadOut = StringTrimLeft($array[$pos], $long)

So now it should be ok. BUT!

I don't know why, the For...Next cycle, so $linky, doesn't click at the right place.

Already tried before to implement such a loop, and neither your, nor mine doesn't work as expected. Don't ask me why.

Apart from that, there was some error on the page I accessed, that's why it stopped always at the same place.

Once continued with the next value, it continued withouth any problem.

Well, the only problem remains with the mouseclick coords, wich in "single mode" does the job, and in a loop doesn't.

Thank you very very much,

Andrew.

Sorry was in a rush. forgot the ")" thanks czardas, I think the problem is once you load from the 1st loop to the second there is not enough time for the Coords. to reset to the right values.

I cleaned up and added a extra sleep after the page is is up, also I would really look into.

#include <IE.au3> 
_IEAction ( ByRef $o_object, $s_action )


 

Parameters

$o_object Object variable of an InternetExplorer.Application 
$s_action Action selection (see remarks) 

 

Return Value

Success: Returns 1 
Failure: Returns 0 and sets @ERROR 
@Error: 0 ($_IEStatus_Success) = No Error 
 3 ($_IEStatus_InvalidDataType) = Invalid Data Type 
 4 ($_IEStatus_InvalidObjectType) = Invalid Object Type 
 5 ($_IEStatus_InvalidValue) = Invalid Value 
@Extended: Contains invalid parameter number

from help

#include <IE.au3>
$oIE = _IE_Example ("form")
$oSubmit = _IEGetObjByName ($oIE, "submitExample")
$hwnd = _IEPropertyGet($oIE, "hwnd")
_IEAction ($oSubmit, "focus")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

; Wait for Alert window, then click on OK
WinWait("Windows Internet Explorer", "ExampleFormSubmitted")
ControlClick("Windows Internet Explorer", "ExampleFormSubmitted", "[CLASS:Button; TEXT:OK; Instance:1;]")
_IELoadWait ($oIE)

;----------------------------------------------------------------- define variables and dependencies
#include <Array.au3> ;include for working with arrays
Global $Paused ;set a global variable
HotKeySet("{PAUSE}", "TogglePause") ;set the Pause/Break key to pause the program
HotKeySet("{ESC}", "Terminate") ;set the ESC key to exit from program
dim $array[1] ;clipboard array
dim $outarray[1] ;storage array
$pos = 0
$errorcatch = ""
$Accession = ""
$Modality = ""
$StudyDesc = ""
$PatientName = ""
$PatientID = ""
$PatientDOB = ""
$UseTitle = "Transport rutier international"
$UseTitle1 = "Catalog Transport"
$UseTitle2 = "Euload - Bursa"
$p1 = "http://catalog.euload.com/index.php?page=" ;page number goes here
$p2 = "&colsort=&colsortord=&showAll=false&srch_company=&srch_city="
$p3 = "&srch_cat=---&srch_country=ro&srch_region=0&srch_word=transport+rutier+international"
;----------------------------------------------------------------- settings
Opt("WinTitleMatchMode", 2) ;setting the window name search mode (so it contains the words we need)
;----------------------------------------------------------------- main
WinActivate($UseTitle2) ;wait for being active the right window with the start page
While 1 ;setting up an infinite loop
for $x=1 to 435 ;there are 435 pages what we need
    $p4 = $p1 & $x & $p2 & $p3 ;define the page where go to
    ClipPut($p4) ;put that page in clipboard

    MouseClick("left",225,60,1,10) ;click at the beginnin of url bar
    Send("+{END}") ;select whatever is there
    Send("{DEL}") ;delete it
    send("^v") ;paste the page url
    send("{ENTER}") ;guess what :)
    ClipPut("") ; clear the clipboard
    Sleep(3000) ;wait for loading the page

        MouseClick(1,700,10)
        Send("{PGUP 4}")


    for $p = 610 to 690 step 40
        MouseClick("left",950,$p,1,0)
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)
    Next
        MouseClick(1,700,10)
        MouseWheel("down",5)
    for $l = 150 to 690 step 40
        MouseClick("left",950,$l,1,0)
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)
        Sleep(2000) ;-- Maybe since there are alot on the page you need more of a rest for the Coord. to be correct.
    Next
        MouseClick(1,700,10)
        MouseWheel("down",2)
    for $m = 500 to 540 step 40
        MouseClick("left",950,$m,1,0)
        WinWaitActive($UseTitle)
        Sleep(2000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)
    Next

Next
WEnd

;----------------------------------------------------------------- declare functions
Func SaveSpore() ;function to copy the page to clipboard and write to the file the info obtained
    Send("^a") ;select text
    Send("^c") ;copy it to clipboard
    Sleep(250)
    $Dump = ClipGet() ;store the dump from clipboard into variable.
    $file = FileOpen("test.csv", 1) ;opening the file for input
    $array =StringSplit(StringStripCR($Dump), @LF) ;split data into single line arrays to parse.
    If Not @error Then

    Local $Nombre[10]
    $Nombre[0] = "Nume Companie:"
    $Nombre[1] = "Adresa:"
    $Nombre[2] = "Oras:"
    $Nombre[3] = "Judet:"
    $Nombre[4] = "Telefon:"
    $Nombre[5] = "Fax:"
    $Nombre[7] = "Pagina WEB:"
    $Nombre[8] = "Limbi de contact:"
    $Nombre[9] = "Domeniu de activitate:"

for $q = 0 to 9
        $pos = _ArraySearch($array, $Nombre[$q], 0, 0, 0, true)
        Select
        Case $Pos = -1
        ;not found
        Case Else
        $ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2))
        _ArrayAdd($outarray, $ReadOut)
        FileWrite($file, $ReadOut & ";")
        EndSelect
Next
    ClipPut("")
    EndIf

    Sleep(250)
    Send("^{F4}") ;close the detail page
    Sleep(250)
    FileClose($file) ;close the file (save it)
EndFunc

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Prgoramma in pausa"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    FileClose($file)
    ClipPut("")
    Exit 0
EndFunc
Edited by lordicast
[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

Good evening.

Like I've said, I'm here again.. So..

@lordicast> I don't want to use the IE UDF, because I am using FF, so I could use the FF UDF, but at the level I am actually, it's almost impossible.. And I putted the @CRLF at the end of a row in the file, wich you ommited.. :mellow:

@czardas>

Do $pinky and $minky click at the right place, or do they also have the same problem?

Yes, they are ok.

Guys, guys, guys.. :P We all missed something about the mouse coordinates.

Two times, it increases with 30, instead of 40. So the For...Next should be like this:

For $l = 150 to 690 step 40
    If $l = 350 Then $l=$l-10
    If $l = 620 Then $l=$l-10
    MouseClick("left",950,$l,1,0)
        WinWaitActive($UseTitle)
        Sleep(1000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)
    Next

Also, I removed the extra Sleep lordicast putted, because it's working fine now. So this is wonderfull.. :party: But now I'm facing another problem, wich is minor, but still a problem.

In this expression:

$ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2))

$array[$pos] contains the search criteria too..

eg.: "Nume Companie: Ancmar SRL" remains like it is, instead of only the name "Ancmar SRL" withouth withouth the tab in front of it (this post doesn't show it, but when saving it to the file, it's there). But this one I will figure out sooner or later, and I will post the whole code again, once it is fully working, because I want to implement an "error handler", wich will act when the script blocks for some reason (e.g. the page wasn't loaded in time so at the MouseClick it would be blocked, etc.), plus I want to put a search criteria too, wich will be very usefull..

All in all, thank you guys very very much. If I will stuck with it again, I will ask you back. :party:

Till then, God bless you all.

Best wishes,

Andrew

Edit:

Ok, I found the problem for the search criteria. So this:

$ReadOut = StringTrimLeft($array[$pos],StringLen($Nombre[$q]+2))

isn't correct, but

$ReadOut = StringTrimLeft($array[$pos],StringLen($Nombre[$q])+2)

it is. :party:

Edited by andrew222

Everybody starts from somewhere..

Link to comment
Share on other sites

Good evening.

Like I've said, I'm here again.. So..

@lordicast> I don't want to use the IE UDF, because I am using FF, so I could use the FF UDF, but at the level I am actually, it's almost impossible.. And I putted the @CRLF at the end of a row in the file, wich you ommited.. :party:

@czardas>

Yes, they are ok.

Guys, guys, guys.. :party: We all missed something about the mouse coordinates.

Two times, it increases with 30, instead of 40. So the For...Next should be like this:

For $l = 150 to 690 step 40
    If $l = 350 Then $l=$l-10
    If $l = 620 Then $l=$l-10
    MouseClick("left",950,$l,1,0)
        WinWaitActive($UseTitle)
        Sleep(1000)
        Call("SaveSpore")
        WinWaitActive($UseTitle1)
    Next

Also, I removed the extra Sleep lordicast putted, because it's working fine now. So this is wonderfull.. :party: But now I'm facing another problem, wich is minor, but still a problem.

In this expression:

$ReadOut = StringTrimLeft($array[$pos], StringLen($Nombre[$q]+2))

$array[$pos] contains the search criteria too..

eg.: "Nume Companie: Ancmar SRL" remains like it is, instead of only the name "Ancmar SRL" withouth withouth the tab in front of it (this post doesn't show it, but when saving it to the file, it's there). But this one I will figure out sooner or later, and I will post the whole code again, once it is fully working, because I want to implement an "error handler", wich will act when the script blocks for some reason (e.g. the page wasn't loaded in time so at the MouseClick it would be blocked, etc.), plus I want to put a search criteria too, wich will be very usefull..

All in all, thank you guys very very much. If I will stuck with it again, I will ask you back. :party:

Till then, God bless you all.

Best wishes,

Andrew

Edit:

Ok, I found the problem for the search criteria. So this:

$ReadOut = StringTrimLeft($array[$pos],StringLen($Nombre[$q]+2))

isn't correct, but

$ReadOut = StringTrimLeft($array[$pos],StringLen($Nombre[$q])+2)

it is. :ILA:

The work around for what your doing is way beyond looking through the firefox udf IMO :mellow: Ur welcome.. "Nick Burn's the company's computer guy!" :P
[Cheeky]Comment[/Cheeky]
Link to comment
Share on other sites

  • 2 weeks later...

Hi everyone again..

Well, I didn't wanted to open a new topic, so I just continue this one, since it's about the rebirth of the same project..

Anyway, I started to take a closer look to the FF UDF, as others suggested me..

Since I am at the beginning, surely I will find other problems as well, but for now, I have a (probably) stupid question, with surely simple answer, for wich I searched a lot, withouth finding the right one.

So, there is a sample page. With more links on it of course. The region (table?! or frame?!) wich I need, is in the middle. I would like to click on them, one by one ("Contacteaza Firma"=details). The code below with _FFSearch() finds correctly the links (as text labels), and the only thing I would like to do, is to click on the links _FFSearch found, in the order they are on the page. Neither for _FFClick(), nor for _FFLinkClick() I couldn't figure out the right options/params to insert in that manner. Of course, I didn't wrote down all the variants I've tried, but I also tried to give as param the XPather link

/html/body/div[2]/table[@id='AutoNumber3']/tbody/tr[3]/td[2]/div/div[1]/center/font/table[@id='AutoNumber1']/tbody/tr[3]/td/p/a

as it is, I tried to short it down like I saw others did, tried to combine it with _FFXpath(), no results.

#include <FF.au3>
$x=0
_FFStart("http://www.afacerilemn.ro/rom/catalog/catalog.php/cat_mobila__1/pa1__6/pa2__7/pa3__8/pa4__9/pa5__10/Country__Romania/Distribution__on/Manufacturer__on/filter__Paleti_Europaleti//pgc__9")
If _FFIsConnected() Then
        for $x=1 to 10
            $sStringToSearch = "Contacteaza Firma"
            If _FFSearch($sStringToSearch) Then
                ;_FFLinkClick($x, "text")
                _FFClick("Contacteaza Firma", "text", 1)
                _FFLoadWait()
                MsgBox(0,"Ok", "Page loaded")
                _FFAction("back")
            Else
                MsgBox(0,"Can't find:", $sStringToSearch)
            EndIf
        Next
        _FFQuit ()
    Else
        MsgBox(0,"Error:", "Can't connect to FireFox!")
EndIf

The problem with the links is, that all has the same text, so the click function does click only on the first one. Also, the ControlClick() doesn't act as I would like.. And

_FFClick( _FFXPath("//a[contains(.,'Contacteaza')]", "", 9))

also click only on the first detail link.

Any ideas? Thank you.

Best regards.

Andrew.

Edit:

Ok, never mind guys, this one I figured out at the end.. It wasn't that hard:

If _FFStart("http://www.afacerilemn.ro/rom/catalog/catalog.php/cat_mobila__1/pa1__6/pa2__7/pa3__8/pa4__9/pa5__10/Country__Romania/Distribution__on/Manufacturer__on/filter__Paleti_Europaleti//pgc__2") Then
    $s1="/html/body/div[2]/table[@id='AutoNumber3']/tbody/tr[3]/td[2]/div/div["
    $s2="]/center/font/table[@class='style1' and @id='AutoNumber1']/tbody/tr[3]/td/p/a[@class='txt_meniu']"
    For $x= 1 to 10
        $page=$s1 & $x & $s2
        _FFClick(_FFXPath($page))
        _FFAction("back")
    Next
_FFQuit()
EndIf
Edited by andrew222

Everybody starts from somewhere..

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