Jump to content

Need help for my first script


Recommended Posts

  • Replies 49
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Maybe you're not very enthusiastic about helping me because you don't understand the purpose of this script.

I'll tell you the purpose of it, and then I hope you will help me make it work. (you will also have the possibility to test it, I'll give you the appropriate links).

Let's say that a chinese person, called John, (let it be me) wants to learn how to use autoit.

Therefore he wants to read all the topics in the autoit forum.

But, as you may know, China has a huge firewall that forbids to go to some pages (see here).

Let the autoit forum be one of these pages.

Then, how can John access the forum ?

He would have to shortcut the chinese firewall.

How can he do that ?

I'm not very good at computer science, so maybe there's an easiest way than the one I'm about to tell you, but anyway, I found a way to do that : using Torpark software (see here, it's the same Wikipedia page as the link before).

The problem of using Torpark is that it slows down the Network a lot. And John can't afford to lose 1 minute every time he clicks a link.

Therefore, I'd like to create a script that uses the Torpark software and copies/pastes every topic of the autoit forum into some .txt, that John can run while doing something else. Afterwards, John will be free to read the autoit topics, as they will be saved on his computer.

Torpark uses a bit of Mozilla Firefox, and that's why I needed to use Mozilla, instead of Internet Explorer.

Now that you know the purpose of making such a script, can you help me to make it work ?

(if you want to test my script, just download the torpark software, by clicking here ).

Link to comment
Share on other sites

Okay, now, let's modificate my first post, according to the previous post.

Hello,

I'd like to write a autoit script that basically goes *to this forum*, opens *every topic* of *this forum*, and *copies/pastes all in a .txt*.

I'd like to use *Torpark* (you can download it from here ) to do these tasks.

Please help me, as I've tried really hard. This might be a bit complicated for a first script.

I'll take the autoitscript forum as an example for the site I'd like to go to, even though it's not the case.

Here is my algorithm (it can be improved - if you have some ideas, they're welcome, I have some ideas too - but for now, let's try to make a script with that algorithm) :

1- Run *Torpark*

2- If a window opens and says that *Torpark* is already running, press enter (it will close the *Torpark* that is running), and go to the step 1-.

3- Wait for 15 seconds for *Torpark* to open.

4a- First possibility: it didn't open. if a window opens and says that Add-on updates are available, then close that window, and continue to the next step (5-). Else, stop the whole script, and create a message window untitled Error saying that *Torpark* didn't open.

4b- Second possibility : it opened. Then continue to the next step (5-).

5- Maximize the *Torpark* window.

6- Press F6, and write the url. For example : http://www.autoitscript.com/forum/index.ph...orum=2&st=0.

7- Wait for the page to load completely (I wrote a function called _wait_load() in order to do that) (*if you want to test my script, you might have to adapt this function for yourself*)

8- If there's a problem loading page (connection issue), then close *Torpark* and go to the step 1-.

9- Search for a word, with ctrl+F. For example, "last post by".

10- Make the mouse go to the selected word. With *Torpark*, it's easy, as the word is overlined in green.

11- Click the word (in my case, it's actually a link right above the word) that was searched.

12- Same as 7-.

13- Same as 8-.

14- *copy paste the topic into a .txt*

15- Come back to the previous page, that shows all the topics (alt+left).

16- Find the next "last post by" (ctrl+G) (Firefox saves the position of the last one that was overlined).

17- Redo the steps 10 to 16 included, 20 times (as there are 20 topics displayed).

18- Redo the steps 6 to 17 included, 2274 times (there are 2274 pages in the subforum "General Help"), but change the last part of the url of the step 6. In my case, the number just needs to be increased by 1, but in the case of the autoitscript forum, the number needs to be increased by 20 : st=0, st=20, st=40, ...

19- Make a message box saying that the script is finished.

This script only needs to be used by me. As a result, I sometimes used specific numbers, that "Autoit window info" gave me.

*Thus, If you want to test my script, you will have to change these specific numbers*

Here is the script that I made :

Func  _wait_load() ;->waits for the page to load
    $initialsum=1293582875 ;*change that for yourself*
    While PixelChecksum(1084,975,1180,988)=$initialsum ;*change the 4 numbers for yourself*
        Sleep(50)
    WEnd
    While PixelChecksum(1084,975,1180,988)=$initialsum
        Sleep(100)
    WEnd
EndFunc  ; ->_wait_load

Opt("WinTextMatchMode", 2) ;*added*

Global $p=0 ; this is the number of the pages that have already been done (see the url below).
Global $c=0 ; this is the number of the topics that have been dealt with successfully (it's just a variable that is meant to count the number of success operations).

While 1
Run("C:\Documents and Settings\John\Desktop\Torpark 2.0.0.3a\Torpark.exe") ;*(or whereever your .exe is)*
If WinWaitActive("Torpark  - Turn any terminal into an anonymous connection.") Then ;*modified*
    Send("{Enter}")
    continueLoop 
EndIf ; If *Torpark* is already running, shut it down and go to step 1.


If Not(WinWait("Mozilla",15)) Then ;*modified*  
    If WinExists("Firefox Add-on Updates") Then
        WinClose("Firefox Add-on Updates") ; close available updates.
    else
    MsgBox(0,"Error","Torpark didn't open") ;modified
    EndIf
EndIf
WinSetState("Mozilla","",@SW_MAXIMIZE) ;*modified*

While $p<=2274 ; number of pages
Sleep(3000)
Send("{F6}http://www.autoitscript.com/forum/index.php?showforum=2&st="&(20*$p)) ; 
_wait_load()
If WinActive("Problem loading page") Then
    Winclose("Problem loading page") 
    ContinueLoop 2
EndIf
Send("^f")
Send("last post by")
For t = 1 to 19 ; there are 20 topics, so this action must be redone 19 times.
local $coord=PixelSearch(400,300,700,950,0x38D878) ;*you might want to change these 4 numbers if you want to test the script*
If Not(@error) Then
    MouseMove($coord[0],$coord[1])
    EndIf
MouseClick("left")
_wait_load()
If WinActive("Problem loading page") Then
    WinClose("Problem loading page")
    ContinueLoop 3
EndIf
; 
; *here will be the copy-paste into a .txt.*
;
$c=$c+1 ; c is the number of successfull *copies/pastes* made during the whole script.
Send("!{LEFT}") ; go to previous page.
Send("^g") ;next research.
Next 
$p=$p+1
WEnd
    
ExitLoop ; If we reached this point, we did all we needed to do. Exit the main loop.
WEnd
MsgBox(0,"Congratulations","The script has ended successfully")

Please help me and tell me if there are any mistakes.

Thanks.

PS: I'm sorry my English is not perfect, I hope you understood me. Otherwise, tell me what you didn't understand, and I'll try to say it again.

Link to comment
Share on other sites

Not to discourage you from your first project but there are really better and more reliable ways to accomplish your goal.

Lets say you just install the Tor bundle (including Vidalia and Privoxy).

All you need now is a decent site ripper like HTTrack or Offline Explorer and set it to the proper proxy address (localhost / 127.0.0.1 Port 8118)

Link to comment
Share on other sites

I actually intend to do more things than just copy/paste.

It was just an example to show you that firefox can actually do some interesting things that IE cannot.

I'd like to use Torpark anyway.

Yet, for now, let's just say that it's just a copy/paste, otherwise it will get too complicated. Right now, the script is not working, so let's not make it even more complicated.

Please help me to get this first script work, and then we can go to the next step.

I repeat, the script is not working. Please help me to fix it.

Link to comment
Share on other sites

Anyone to help me make my script work, please ?

Learn to write Firefox addons in .XUL and you can access its APIs from the inside. The pain here is coming from trying to manipulate the Firefox app from the outside, which they go out of their way to prevent at Mozilla, to the extent possible in a Windows environment.

:)

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

What PsaltyDS said is important to understand. Firefox tries very hard to prevent other programs from having access to manipulate it. What firefox does provide is a way to make plugins that can do everything you are wanting AutoIt to do. If you wrote this plugin to run automatically all you would have to do with AutoIt is start firefox and firefox would do the rest. It's very difficult to help when every detail of every step (not just what you want it to do) must be clear. Yet it can't be given the way firefox works.

You can still do what you want with AutoIt but you must test each step yourself. Anybody that tries to help would need to have firefox and any supporting programs and physically repeat the testing. Let's look at your steps:

1- Use If WinExists("firefox") then WinKill("firefox") --- See help file.

This skips opening then closing if firefox is already open.

2 - Run firefox. Use: $ret = Run ('firefox.exe "www.autoitscript.com/forum/", "", @SW_MAXIMIZE)

Adding the site to the argument skips the F6 stuff address stuff and @SW_MAXIMIZE skips the maximize stuff in your steps.

3 - If Not $ret then error: firefox failed to open.

4 - WinWaitActive() --- Firefox

5 - Do your _wait_load() here.

I would have to actually test the remainder of your steps and I don't even know if what I would call a success would work for you. You can just send CTRL-S and save the whole page in whatever format you want. You can then open these files in autoit and strip out whatever you want.

Link to comment
Share on other sites

The things you're talking about are way too complicated for me.

I'm just starting with autoit, and I'd just want a script that has a good chance to work, even if it's not perfect.

I'm not good enough to make a firefox plugin or anything else like that (and it sounds to be a very long and complicated task).

I think the algorithm I wrote in the post 23 has a good chance to work, but it's not working. There should be some mistakes in the code.

Please help me to correct these mistakes, so that the script can work.

In order to test the script and find out the errors, maybe you should download torpark and try the script yourself (normally,you will only need to change some numbers, according to the size of your screen - you can get these numbers with autoit window info).

Thanks for helping me to correct it.

Link to comment
Share on other sites

Ok, I tried to make as much sense as I could out of your code and rewrote it. I just assume your _wait_load() actually works. I'm very sure it still has problems. The source of some problems in finishing this script is predictable. Basically when recovering from an error much of the previous work will get repeated, but only for that page. It could be fixed with the variable $c and CTRL-Gs. A run error or shutdown of any kind would force a complete repeat unless you stored those variables in file. I haven't tested ANY of this code.

Opt("WinTextMatchMode", 2) ;*added*
Dim $coord, $c=0
Global $p=0
; As per description
; Not sure why you repeat the same loop twice in _wait_load() but I copied the same.

_reset()

While $p<=2274
        Send("^f")
  For t = 1 to 19
        Send("^g") ;Doesn't matter if Send("^f") already selected it, still needed for loop.
        Send("last post by")
        $coord=PixelSearch(400,300,700,950,0x38D878)
    If Not(@error) Then
        MouseMove($coord[0],$coord[1])
    EndIf
        MouseClick("left")
        _wait_load(); See the modification to _wait_load()
    ; 
; *here will be the copy-paste into a .txt.*
    ;
        $c=$c+1 
        Send("!{LEFT}")
        _wait_load()
  Next
    $p=$p+1
    Send("{F6}http://www.autoitscript.com/forum/index.php?showforum=2&st="&20*$p)
    _wait_load()
WEnd
MsgBox(0,"Congratulations","The script has ended successfully")

Func _reset()
While 1
            WinKill("Torpark.exe")
            ProcessWaitClose("Torpark.exe",15000); =15 seconds
            Run("C:\Documents and Settings\John\Desktop\Torpark 2.0.0.3a\Torpark.exe")
;Fatal error occurs if Run fails!!! See RunErrorsFatal option.
            WinWait("Torpark  - Turn any terminal into an anonymous connection.","",15000)
            WinActivate("Torpark  - Turn any terminal into an anonymous connection.")
            Sleep(1000); 1 second
            Send("{Enter}")
    If Not ProcessExists("firefox.exe") Then
            Run("firefox.exe","",@SW_MAXIMIZE)
;Fatal error occurs if Run fails!!! See RunErrorsFatal option.
            WinWait("Mozilla","",15000)
        If WinExists("Firefox Add-on Updates") Then
            WinClose("Firefox Add-on Updates")
        EndIf
            WinActivate("Mozilla")
    Else
        WinActivate("Mozilla")
        WinSetState("Mozilla","",@SW_MAXIMIZE)
    EndIf
        Send("{F6}http://www.autoitscript.com/forum/index.php?showforum=2&st="&20*$p)
        Local $initialsum=1293582875
;_wait_load() copied here to avoid a possible function recursion if the internet connection is lost.
    While PixelChecksum(1084,975,1180,988)=$initialsum
       Sleep(1000); =1 second
    WEnd
    If Not WinActive("Problem loading page") Then
        ExitLoop
    EndIf
WEnd
EndFunc

Func  _wait_load()
    Local $initialsum=1293582875 
    While PixelChecksum(1084,975,1180,988)=$initialsum ;Why twice?
       Sleep(1000); =1 second
    WEnd
    If WinActive("Problem loading page") Then
        _reset()
    EndIf
    Sleep(2000); 2 seconds
EndFunc
Link to comment
Share on other sites

Thanks a lot (really!) for your answer. I'm going to read your comments carefully, and try the script.

I'll edit this post once I've tried it.

I'm editing the post while I'm testing it (refresh to see my last comments).

- I've changed the line 37 (Run("C:\Documents and Settings\John\Desktop\Torpark 2.0.0.3a\Torpark.exe")), according to where my .exe is in my hard drive.

- At lines 43 and 44, did you mean (Run("C:\Documents and Settings\John\Desktop\Torpark 2.0.0.3a\Torpark.exe") ?

(it's not firefox.exe but torpark.exe)

- When I run the script, it says that line 11, ' Error: "For" statement is badly formatted. ' --> a $ was missing.

Concerning your question about _wait_load() :

- Firstly, you said at line 5 that you copied the same, but you actually removed the second loop.

- Here was my algorithm :

0/ Use Autoit window info to find out the coordinates of the rectangle where the progress bar appears.

1/ pixelchecksum the area of that rectangle, when the progress bar is not here (I wrote a script in order to do that, that waited enough time to be sure that the loading was finished, and then calculated the pixelchecksum). Save it in a variable named $initialsum.

3/ When the function is called : make a pixelchecksum of the rectangle. If this pixelchecksum is not equal to the initialsum, then it means that the progress bar is here. Redo the step 3, until it is equal. When it is, the function ends.

(in order not to overload the CPU, wait 100ms between each loop). BUT : a problem can occur : what if the pixelchecksum of the step 3 is made before the progress bar appears ? I mean, when you write an url and press enter, a laps of time can occur before the progress bar actually starts. Therefore, i wrote a step 2 :

2/ When the function is called : make a pixelchecksum of the rectangle. As long as the progress bar hasn't started (i.e. as long as this pixelchecksum is equal to initialsum), wait for it to appear, by redoing the step 2. As soon as the pixelchecksum is not equal to initialsum, go to step 3.

(in order not to overload the CPU, wait 50ms between each loop - a little bit less than the step3, as this operation should be faster.).

Edit: the script doesn't work. It seems that the script presses "Cancel" when Torpark begins.

Would you mind to download torpark and to test it by yourself ?

Edited by Elishac
Link to comment
Share on other sites

The 2.0.0.3a version doesn't look corrupted to me (I can give you my link if you want).

This xB Browser ver: 2.0.0.12b looks very different. I don't know how it works, nor what windows might appear (whereas I know it for the 2.0.0.3a version, that looked like firefox).

Nonetheless, I don't mind, as long as the script works :).

Link to comment
Share on other sites

Water got to my computer.. Don't ask :) I pulled an old win98 machine out of storage in the library and got it to working. It'll take me a few days to get everything back, sorry.

Win98 is so much faster if I just didn't have to reboot so freakin often.

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