Jump to content

Firefox URL into Array


Kashgari
 Share

Recommended Posts

Hi, I am trying to create a script to automate something with Firefox. It is in these steps.

1. Read a text file read each line in to array. (these are URL)

2. Use Firefox to visit each URL, loop until all the array finishes.

3. While visiting each line do something and move to next URL.

I think this maybe easier with IE , but I want to use Firefox.

I have read a lot of posts and help files, examples are either too easy or too difficult for me.

Thanks.

Edited by Kashgari
Link to comment
Share on other sites

To read each line of a file, you can use _FileReadToArray or you can use FileReadLine in a loop. To visit websites, look at _FFStart and _FFOpenURL. To go through each url, loop through the array from _FileReadToArray or use FileReadLine each time. Post some code with what you have tried next time.

Link to comment
Share on other sites

Ok, after reading number of posts and help file I come make following script, it looks fine but generates no result.

Please help.

#include <file.au3>
#Include <FF.au3>

Dim $aRecords
If Not _FileReadToArray("url.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    _FFConnect()
     If _FFIsConnected() Then
    _FFOpenUrl($x,$aRecords[$x])
    Sleep(5000)
    Endif
Next
Link to comment
Share on other sites

For $x = 1 to $aRecords[0]
    _FFConnect()
     If _FFIsConnected() Then
    _FFOpenUrl($x,$aRecords[$x])
    Sleep(5000)
    Endif
Next

Have you looked after the console output from your editor?

1) First "problem" - you made in every loop a new connection to FireFox - one connection is enough.

2) The first parameter from _FFOpenURL is the URL - you have there an integer

3) The second parameter from _FFOpenURL is a boolean for $bLoadWait

The last two things must you show many errors in the console.

_FFOpenURL

_FFConnect()

If _FFIsConnected() Then
  For $x = 1 to $aRecords[0]
    _FFOpenUrl($aRecords[$x])
    Sleep(5000)
  Next
EndIf
Link to comment
Share on other sites

What is the output in your editor console?

Sorry I am still learning, I do not know how to use editor console.

Are the URLs from your file really in this array?

Yes, it is a simple text file with five lines, each line is one URL.

Actually this test is working

Msgbox(0,"", $aRecords[$x])

But when I change that line to _FFOpenUrl($aRecords[$x]) script does nothing.

This is the whole code.

#include <file.au3>
#Include <FF.au3>

Dim $aRecords
If Not _FileReadToArray("url.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
_FFConnect()

If _FFIsConnected() Then
  For $x = 1 to $aRecords[0]
    _FFOpenUrl($aRecords[$x])
    Sleep(5000)
  Next
EndIf
Link to comment
Share on other sites

Sorry I am still learning, I do not know how to use editor console.

Yes, it is a simple text file with five lines, each line is one URL.

Actually this test is working

Msgbox(0,"", $aRecords[$x])

But when I change that line to _FFOpenUrl($aRecords[$x]) script does nothing.

This is the whole code.

#include <file.au3>
#Include <FF.au3>

Dim $aRecords
If Not _FileReadToArray("url.txt",$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
_FFConnect()

If _FFIsConnected() Then
  For $x = 1 to $aRecords[0]
    _FFOpenUrl($aRecords[$x])
    Sleep(5000)
  Next
EndIf

OK, but have you any error messages from the FF.au3 in the console of your editor? I think you can open it in SciTe with F8 - I don't use this editor.

Is the connection to FireFox working?

You can check it with:

If _FFConnect() Then MsgBox(0,"", "Connected")

Edited by Stilgar
Link to comment
Share on other sites

Dear Stilgar,

Thank you very much for your attention.

I got it worked. But something strange happened. For making thing faster instead of entering web url, I have made 5 pages, in my computer (I am on Xampp) to do the test such as

http://localhost/test/file1.html

http://localhost/test/file2.html

...

I can visit these pages with no problem, but the script did not able to visit them, as soon as I have changed URL to online URLs

it worked.

Problem solved, but is it normal?

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