Jump to content

I need help reading some lines from a .txt


 Share

Recommended Posts

Hello everyone.

I have the following script:

#include <File.au3>
#include <IE.au3>

$file = "lines.txt"
FileOpen($file)
$line = FileReadLine($file, 1)
$line2 = FileReadLine($file, 2)
FileClose($file)

$o_IE = _IECreate ("x.html",0,1)
$o_IE.navigate($URL, 0, 0, $PostData ,$Header)
Sleep(600)
WinWaitActive("Hello")
Sleep(1000)
Send($line)
Send("{TAB}")
Send($line2)

The thing I am trying to do is, to automatically login using a username (line1 -> line1 in the txt file.), and a password (line2 - sencond line in the txt file), and it only reads the first line from the file.

Can I get some help?:(

Link to comment
Share on other sites

Are you sure your problem is the reading of the lines? That part looks ok to me.

Although I would change it to:

$file = FileOpen("lines.txt")

$line = FileReadLine($file, 1)

$line2 = FileReadLine($file, 2)

FileClose($file)

Have you put a msgbox(0, "TEST", $line & @CRLF & $line2)? see what you get?

I wouldn't do the send keys method of sending the info to the IE Webpage though I'd do ControlSend.

Terry

Edited by mattw112
Link to comment
Share on other sites

You don't need FileOpen() at all, just read the file.

$aArray = StringRegExp(FileRead("lines.txt"), "^(.+)(?:\v)(.+)(?:\v|$)", 1)

If NOT @Error Then
    $sUser = $aArray[0]
    $sPass = $aArray[1]
    MsgBox(0, "Result", $sUser & @CRLF & $sPass)
EndIf

Edit: If the file is not large then you can also use this,

$aArray = StringRegExp(FileRead("lines.txt"), "(?m:^)(.+[^\v\z])", 3)
If NOT @Error Then
    $sUser = $aArray[0]
    $sPass = $aArray[1]
    MsgBox(0, "Result", $sUser & @CRLF & $sPass)
EndIf
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thank you very much guys.

I got one more question. What about if I want AutoIT to login with the first username(1st line) and the first password(2nd line), and than logout and login into the second account (3rd line), with the second password(4th line) and so on?

Thank you very much for responding to my thread.

Link to comment
Share on other sites

If your using my code then since you already know that $aArray[0] is the first username and $aArray[1] is the first password then it follws that the next set will be $aArray[3] and $aArray[4] so you can work it out from there. You may also be able to use something along the lines of

For $i = 0 To Ubound($aArray) -2 Step 2
    MsgBox(0, "Result", "User: " & $aArray[$i] & @CRLF & "Password: " & $aArray[$i +1])
Next

Just replace the message box with whatever you need to do.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thank you for your replies.

Ok, so i did this:

$aArray = StringRegExp(FileRead("lines.txt"), "^(.+)(?:\v)(.+)(?:\v|$)", 1)


If NOT @Error Then
    $1User = $aArray[0]
    $1Pass = $aArray[1]
    $2User = $aArray[3]
    $2Pass = $aArray[4]
    MsgBox(0, "Result", $1User & @CRLF & $1Pass)
EndIf

But, I still get this errors:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Slym\Desktop\AutoIt\full pt Title.au3"    
C:\Documents and Settings\Slym\Desktop\AutoIt\full pt Title.au3 (11) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$2Pass = $aArray[4]
$2Pass = ^ ERROR
>Exit code: 1    Time: 0.319
Link to comment
Share on other sites

I think maybe there's a simple typo in the code you have referencing the array, assuming there are at least four lines of text in the file being read.

Your code

$aArray = StringRegExp(FileRead("lines.txt"), "^(.+)(?:\v)(.+)(?:\v|$)", 1)


If NOT @Error Then
    $1User = $aArray[0] ; line 1
    $1Pass = $aArray[1] ; line 2
    $2User = $aArray[3] ; line 4
    $2Pass = $aArray[4] ; line 5
    MsgBox(0, "Result", $1User & @CRLF & $1Pass)
EndIf

Try this code and see if it completes

$aArray = StringRegExp(FileRead("lines.txt"), "^(.+)(?:\v)(.+)(?:\v|$)", 1)


If NOT @Error Then
    $1User = $aArray[0] ; line 1
    $1Pass = $aArray[1] ; line 2
    $2User = $aArray[2] ; line 3
    $2Pass = $aArray[3] ; line 4
    MsgBox(0, "Result", $1User & @CRLF & $1Pass)
EndIf

However, you still the risk of the same error if you just assume StringRegExp will return an array with at least four elements.

[Fixed typo in post, how ironic :)]

Edited by tehdon
Link to comment
Share on other sites

I used this code :

$aArray = StringRegExp(FileRead("lines.txt"), "^(.+)(?:\v)(.+)(?:\v|$)", 1)


If NOT @Error Then
    $1User = $aArray[0] ; line 1
    $1Pass = $aArray[1] ; line 2
    $2User = $aArray[2] ; line 3
    $2Pass = $aArray[3] ; line 4
    MsgBox(0, "Result", $1User & @CRLF & $1Pass)
EndIf

But I still get :

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3"    
C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3 (10) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
$2User = $aArray[2]
$2User = ^ ERROR
>Exit code: 1    Time: 0.329

:(

Edited by Slymy
Link to comment
Share on other sites

It still looks as if at least one more element is being referenced than what exists in the $aArray.

Try GEOSoft's (slightly modified) code:

$aArray = StringRegExp(FileRead("lines.txt"), "^(.+)(?:\v)(.+)(?:\v|$)", 1)

For $i = 0 to Ubound($aArray) -2 Step 2
    If($i+1 < UBound($aArray)) Then
        MsgBox(0,"Result","User: " & $aArray[$i] & @CRLF & "Password: " & $aArray[$i+1])
    EndIf
Next

I think this will work, I'm pretty mushy brained at this point of the day, though.

Link to comment
Share on other sites

Did this :

$2User = FileReadLine("lines.txt", 3);
$2Pass = FileReadLine("lines.txt", 4);
$3User = FileReadLine("lines.txt", 5);
$3Pass = FileReadLine("lines.txt", 6);
$4User = FileReadLine("lines.txt", 7);
$4Pass = FileReadLine("lines.txt", 8);
$5User = FileReadLine("lines.txt", 9);
$5Pass = FileReadLine("lines.txt", 10);
$6User = FileReadLine("lines.txt", 11);
$6Pass = FileReadLine("lines.txt", 12);
$7User = FileReadLine("lines.txt", 13);
$7Pass = FileReadLine("lines.txt", 14);
$8User = FileReadLine("lines.txt", 15);
$8Pass = FileReadLine("lines.txt", 16);
$9User = FileReadLine("lines.txt", 17);
$9Pass = FileReadLine("lines.txt", 18);
$10User = FileReadLine("lines.txt", 19);
$10Pass = FileReadLine("lines.txt", 20);

And it worked. Hehe.

Now I got one more question. :)

How can I get AutoIT to pass over an account if the account is not valid?

I mean, it's a browser thingy, if the account or pwd is typed wrong, it shows this error, with RED font : Your email address,or password is incorrect. Please try again.

How can I make autoit to jump to the next account (line) if it gets this error?.

Thank you very much :(.

Link to comment
Share on other sites

It's pretty much the same method but you then have to get the URL for that page and check for the string. You can use this inside your loop.

$sUrl = "enter the page url here"
$sCheck = BinaryToString(InetRead($sUrl))
If StringRegExp($sCheck, "(?i)".+email.+password.+try\sagain\..+") Then ContinueLoop
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Ok so now I got this code :

hellExecute("x.html")
WinWaitActive("Login - Mozilla Firefox")
Sleep(1000)
Send($1User)
Sleep(2000)
Send("{TAB}")
Send($1Pass)
Send("{Enter}")
$sUrl = "x.html"
$sCheck = BinaryToString(InetRead($sUrl))
If StringRegExp($sCheck, "(?i)".+email.+password.+try\sagain\..+") Then ContinueLoop
WinWaitActive("Hello - Mozilla Firefox")

And I get this error :

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3"    
C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3 (40) : ==> Unterminated string.: 
If StringRegExp($sCheck, "(?i)".+email.+password.+try\sagain\..+") Then ContinueLooP 

>Exit code: 1    Time: 0.211
Link to comment
Share on other sites

Ok so now I got this code :

hellExecute("x.html")
WinWaitActive("Login - Mozilla Firefox")
Sleep(1000)
Send($1User)
Sleep(2000)
Send("{TAB}")
Send($1Pass)
Send("{Enter}")
$sUrl = "x.html"
$sCheck = BinaryToString(InetRead($sUrl))
If StringRegExp($sCheck, "(?i)".+email.+password.+try\sagain\..+") Then ContinueLoop
WinWaitActive("Hello - Mozilla Firefox")

And I get this error :

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3"    
C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3 (40) : ==> Unterminated string.: 
If StringRegExp($sCheck, "(?i)".+email.+password.+try\sagain\..+") Then ContinueLooP 

>Exit code: 1    Time: 0.211

That was my fault, I don't know how that extra quote snuck in there.

If StringRegExp($sCheck, "(?i).+email.+password.+try\sagain\..+") Then ContinueLoop

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

GEOSoft thank you very much for your help. I appreciate it.

Now I get this error :-?

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3"    
C:\Documents and Settings\Slym\Desktop\AutoIt\5.au3 (40) : ==> "ExitLoop/ContinueLoop" statements only valid from inside a For/Do/While loop.:
If StringRegExp($sCheck, "(?i).+email.+password.+try\sagain\..+") Then ContinueLoop
Link to comment
Share on other sites

That's because it was written to be used in a loop like what I posted in my first reply but you could replace the continueloop with a message box or any other action you want to take in the event of an error. It was written that way because you requested that in the event of that error it would continue on to the next user/password in the set where the set as returned by the first regex is an array. In order to work your way through an array sequentialy we do it in a loop.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Umm, I guess I'm just to dumb to make it work. :()

Can you please help me out a bit by modifying my code a bit please?

Here's my code:

#include <File.au3>
#include <IE.au3>

$aArray = StringRegExp(FileRead("lines.txt"), "^(.+)(?:\v)(.+)(?:\v|$)", 1)
$2User = FileReadLine("lines.txt", 3);
$2Pass = FileReadLine("lines.txt", 4);
$3User = FileReadLine("lines.txt", 5);
$3Pass = FileReadLine("lines.txt", 6);
$4User = FileReadLine("lines.txt", 7);
$4Pass = FileReadLine("lines.txt", 8);
$5User = FileReadLine("lines.txt", 9);
$5Pass = FileReadLine("lines.txt", 10);
$6User = FileReadLine("lines.txt", 11);
$6Pass = FileReadLine("lines.txt", 12);
$7User = FileReadLine("lines.txt", 13);
$7Pass = FileReadLine("lines.txt", 14);
$8User = FileReadLine("lines.txt", 15);
$8Pass = FileReadLine("lines.txt", 16);
$9User = FileReadLine("lines.txt", 17);
$9Pass = FileReadLine("lines.txt", 18);
$10User = FileReadLine("lines.txt", 19);
$10Pass = FileReadLine("lines.txt", 20);

If NOT @Error Then
    $1User = $aArray[0] ; line 1
    $1Pass = $aArray[1] ; line 2
    MsgBox(0, "Result", $1User & @CRLF & $1Pass)
EndIf

ShellExecute("x.html")
WinWaitActive("Login - Mozilla Firefox")
Sleep(1000)
Send($1User)
Sleep(2000)
Send("{TAB}")
Send($1Pass)
Send("{Enter}")
$sUrl = "x.html"
$sCheck = BinaryToString(InetRead($sUrl))
If StringRegExp($sCheck, "(?i).+email.+password.+try\sagain\..+") Then ContinueLoop 
WinWaitActive("Hello - Mozilla Firefox")

Thank you very much.

Edited by Slymy
Link to comment
Share on other sites

Umm, I guess I'm just to dumb to make it work. :()

Can you please help me out a bit by modifying my code a bit please?

Thank you very much.

I will but I have to lay down for a while. I'll look at it when I come back.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

I'm starting this fresh. You are using 2 methods to achieve the same thing so it's no wonder you are confused. Make a choice between using FileReadLine and using the regular expression. Also the

If @Error Then
line comes after the StringRegExp() as I showed earlier, by putting it where it is you are checking the last FileReadLine() statement and then the code that is inside the If statement makes no sense at all. I gave you all the code that you should need if you look at my previous posts.

Now I need to clarify one point again.

Do you want to move on to the second, third etc. user ONLY if the first fails or are you trying to log in to several accounts at the same time?

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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