arryo Posted October 4, 2009 Share Posted October 4, 2009 (edited) Hi guys, I need your help. The problem: http://www.youtube.com/user/KanemaruAyouma I want Autoit to click the "Add as Friend"-Button, but it doesnt refer to a url. So that's the problem. I cant use Mouseclick, cause the styles are always different. "<span id="aProfileAddFriend" class="nowrap"><a href="#" onclick="add_friend('KanemaruAyouma'); return false;">Als Freund hinzufügen</a>" is the code from the site. Can anyone help me, or got an idea? Edited October 10, 2009 by arryo Link to comment Share on other sites More sharing options...
mistersquirrle Posted October 4, 2009 Share Posted October 4, 2009 I don't' know if you can put this into your script, but this does it #include <IE.au3> $oIE = _IECreate("http://www.youtube.com/user/KanemaruAyouma") ;create a IE window, and go to user page _IELinkClickByText($oIE, "Add as Friend") ;Click the link that says "Add as Friend" We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
arryo Posted October 4, 2009 Author Share Posted October 4, 2009 I don't' know if you can put this into your script, but this does it #include <IE.au3> $oIE = _IECreate("http://www.youtube.com/user/KanemaruAyouma") ;create a IE window, and go to user page _IELinkClickByText($oIE, "Add as Friend") ;Click the link that says "Add as Friend" Thx, helped me alot. New Question: How can I find out quickly if there is a certain message displayed on a Site in the Internet explorer? Link to comment Share on other sites More sharing options...
mistersquirrle Posted October 4, 2009 Share Posted October 4, 2009 (edited) certain message like what? You can use _IEBodyReadText and that will return all the text inside the <Body></Body> tag... That should be everything (as long as it's text) and then use StringInStr to find if your message is there Edit: it's _IEBodyReadText... not HTML Edited October 4, 2009 by mistersquirrle We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
arryo Posted October 5, 2009 Author Share Posted October 5, 2009 (edited) certain message like what? You can use _IEBodyReadText and that will return all the text inside the <Body></Body> tag... That should be everything (as long as it's text) and then use StringInStr to find if your message is thereEdit: it's _IEBodyReadText... not HTMLAye.But I need the HTML; its ok.The next thing is:I save the HTML of a site in a variable.Then my script saves the html in a .txt file.Now the script checks each line of the .txt file if it contains the string "/user/" - if it contains the string then it SHOULD save it into another .txt <- this doesnt workHere is my code:$d = @DesktopDir&"\" $t = 1 $e = 1 Do $txt1 = $d&"Youtube\youtubetemp.txt" ;reads the file that contains the html $file1 = FileOpen($txt1, 0) $arr =FileReadLine($txt1, $e) $textcheck = StringRegExp($arr, "/user/", 0) ;checks if the line contains "/user/" if $textcheck = 1 Then $txt2 = $d&"Youtube\userlist.txt" ;writes the line into a new .txt $file2 = FileOpen($txt2, 1) FileWriteLine($file2, FileReadLine($txt1, $t)) FileClose($txt2) $t = $t + 1 EndIf $e = $e + 1 FileClose($txt1) Until $e = 10000 ;<--- I think also this is bad. Runs until the html .txt endedPS: Couldn't find any good code style, sorry.Next step in my script would be:Get the usernane.(if it contains "/user/" in step 1, then the full string is always href="/user/shadow3lement" (last one is the username). How to get it?PS: Here is an example of the full HTML Code.Main goal: Get all the usernames.Hmmm the forum upload doesnt work so its here:http://rapidshare.com/files/289027850/youtubetemp.txt.html Edited October 5, 2009 by arryo Link to comment Share on other sites More sharing options...
mistersquirrle Posted October 5, 2009 Share Posted October 5, 2009 Aye. But I need the HTML; its ok. The next thing is: I save the HTML of a site in a variable. Then my script saves the html in a .txt file. Now the script checks each line of the .txt file if it contains the string "/user/" - if it contains the string then it SHOULD save it into another .txt <- this doesnt work Here is my code: $d = @DesktopDir&"\" $t = 1 $e = 1 Do $txt1 = $d&"Youtube\youtubetemp.txt" ;reads the file that contains the html $file1 = FileOpen($txt1, 0) $arr =FileReadLine($txt1, $e) $textcheck = StringRegExp($arr, "/user/", 0) ;checks if the line contains "/user/" if $textcheck = 1 Then $txt2 = $d&"Youtube\userlist.txt" ;writes the line into a new .txt $file2 = FileOpen($txt2, 1) FileWriteLine($file2, FileReadLine($txt1, $t)) FileClose($txt2) $t = $t + 1 EndIf $e = $e + 1 FileClose($txt1) Until $e = 10000 ;<--- I think also this is bad. Runs until the html .txt ended PS: Couldn't find any good code style, sorry. Next step in my script would be: Get the usernane. (if it contains "/user/" in step 1, then the full string is always href="/user/shadow3lement" (last one is the username). How to get it? PS: Here is an example of the full HTML Code. Main goal: Get all the usernames. $d = @DesktopDir & "\" $t = 1 $e = 1 Do $txt1 = $d & "Youtube\youtubetemp.txt" ;reads the file that contains the html $file1 = FileOpen($txt1, 0) $arr = FileReadLine($txt1, $e) $textcheck = StringRegExp($arr, "/user/", 0) ;checks if the line contains "/user/" If $textcheck = 1 Then $txt2 = $d & "Youtube\userlist.txt" ;writes the line into a new .txt $file2 = FileOpen($txt2, 1) FileWriteLine($file2, FileReadLine($txt1, $t)) FileClose($txt2) $t = $t + 1 EndIf $e = $e + 1 FileClose($txt1) Until $e = 10000 ;<--- I think also this is bad. Runs until the html .txt ended use [ autoit][ /autoit] code tags for that, that's the best. Also in SciTE use Tidy (default ctrl+t) to format it. and I change my orginal post, I had _IEBodyReadHTML() which returns the HTML inside the <body> tag of the document, which should be all that you need (if not you could always use _INetGetSource()). If you don't mind waiting a little extra (second or so on a good connection) I'd say use _INetGetSource() since _IEBodyReadHTML() requires you to be on that page, created with _IECreate(), and it formats it weird. I have to go home now, but I'm working on something. Post in a bit We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
mistersquirrle Posted October 5, 2009 Share Posted October 5, 2009 All right, based off what the youtubetemp.txt file you linked to, I came up with this: #include <Inet.au3> #include <String.au3> #include <Array.au3> ;$Source = _INetGetSource("www.youtube.com") ;Put it the webpage were all these usernames are here ;$Source = FileRead(@DesktopDir & "\youtubetemp.txt") ;I used this for referance, since I didn't know what the address was of the source $Users = _StringBetween($Source, "/user/", '"') _ArraySort($Users) For $i = 0 To UBound($Users) - 1 If UBound($Users) - 1 < $i Then ExitLoop While 1 If StringInStr($Users[$i], $Users[$i + 1], 1) Then _ArrayDelete($Users, $i) If UBound($Users) - 1 <= $i Then ExitLoop Else ExitLoop EndIf WEnd Next _ArraySort($Users) _ArrayDisplay($Users) that'll get all the users, and delete the duplicates. That should take care of that, and then you can just use a for loop going through the $User array to add friends, or do whatever it is you want to do. We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
arryo Posted October 6, 2009 Author Share Posted October 6, 2009 (edited) Thanks, works perfectly! :-D But I have a question, how the hell can I "use" them? I want them to put in a new Array, but: Local $u[50] [...the script...] $o = 1 ; <- i dont want the first name Do $u[$o] = $Users[$o] $o = $o + 1 Until $u[$o] = "" doesnt work :/ I can assign the full code, if you want. Edited October 6, 2009 by arryo Link to comment Share on other sites More sharing options...
arryo Posted October 6, 2009 Author Share Posted October 6, 2009 (edited) Hmm, I cant edit my post, wtf? Well here is the full code: expandcollapse popup#include <Inet.au3> #include <String.au3> #include <Array.au3> #include <IE.au3> $ver = "Youtube GetUsers 1.0.au3" $d = @DesktopDir&"\" $ie = @ProgramFilesDir&"\Internet Explorer\iexplore.exe" HotKeySet ( "{Pause}" , "pause" ) ;pauses the script $pause = False Func pause () if $pause = false then $pause = true While $pause = true Sleep(1) WEnd Else $pause = false endif Endfunc HotKeySet ( "{Esc}" , "Ende" ) ;closes the script Func Ende () ProcessClose("Debug.exe") Exit EndFunc $q1 = MsgBox(4, $ver, "Start? Hinweis: Exit zum jederzeitigen Beenden des Scripts! Nur für Internet Explorer!") If $q1 = 7 Then MsgBox(0, $ver, "Abgebrochen.") Exit EndIf $cLoop = 1 While $cLoop = 1 $p = InputBox ($ver,"Wähle deinen iexplore.exe Pfad (sollte korrekt sein)", $ie,"" , 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $ff = $p ExitLoop EndIf WEnd $cLoop = 1 While $cLoop = 1 $p = InputBox ($ver,"User you want to get the new users from? (GetSubscribers)", "athenewins","" , 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $getnewu = $p ExitLoop EndIf WEnd $cLoop = 1 While $cLoop = 1 $p = InputBox ($ver,"Begin with upage = ...", "0","" , 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $page = $p ExitLoop EndIf WEnd $cLoop = 1 While $cLoop = 1 $p = InputBox ($ver,"How many users you want to get? (40,80,120,160 ....), 0 = infinite", "0","" , 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else if $p = 0 Then $iuserget = 100000 ; ... to better else $iuserget = $p Endif ExitLoop EndIf WEnd $txt = $d&"Youtube Bot\userlist.txt" ;the path where to save the Usernames $file = FileOpen($txt, 0) If $file = -1 Then ;create new file (to better) Opt("SendKeyDelay", 30) Run("notepad.exe"); Open Notepad (create new file) WinWaitActive("Unbenannt - Editor") WinMove("Unbenannt - Editor", "", 0, 0, 1160, 842) Send ("^{s}") Send ($d&"Youtube Bot\userlist.txt") Sleep(500) Send ("{ENTER}") Sleep(500) Send ("!{F4}") Endif FileClose($txt) Opt("SendKeyDelay", 0) Run("Debug.exe") $mIE = _IECreate ("www.youtube.com") ;open youtube WinMove ( "", "", 0, 0, 1160, 842) Local $u[$iuserget] $un = 0 $o = 0 Do call("getuser") Sleep(1000) $z = 1 Do if $u[$z] = "" Then $z = 100 Else $txt = $d&"Youtube Bot\userlist.txt" $file = FileOpen($txt, 1) FileWriteLine($file, $u[$z]) FileClose($txt) Endif Until $z = 100 $un = $un + 40 Until $un >= $iuserget MsgBox(1, "Finished!", "Finished. Done: "&$iuserget) ProcessClose("Debug.exe") ;close the Debug.exe Local $u[50] Func getuser () ;get the users _IENavigate ($mIE, "http://www.youtube.com/profile?user="&$getnewu&"&view=subscribers&start="&$un) ;open youtube user _IELoadWait($mIE) $Source = _INetGetSource("http://www.youtube.com/profile?user="&$getnewu&"&view=subscribers&start="&$un) ;Put it the webpage were all these usernames are here $Users = _StringBetween($Source, "/user/", '"') _ArraySort($Users) For $i = 0 To UBound($Users) - 1 If UBound($Users) - 1 < $i Then ExitLoop While 1 If StringInStr($Users[$i], $Users[$i + 1], 1) Then _ArrayDelete($Users, $i) If UBound($Users) - 1 <= $i Then ExitLoop Else ExitLoop EndIf WEnd Next _ArraySort($Users) $o = 1 Do $u[$o] = $Users[$o] $o = $o + 1 Until $u[$o] = "" EndFunc The goal is the entire thing should also work in the background Edited October 6, 2009 by arryo Link to comment Share on other sites More sharing options...
mistersquirrle Posted October 6, 2009 Share Posted October 6, 2009 (edited) But I have a question, how the hell can I "use" them? I want them to put in a new Array, but: Local $u[50] [...the script...] $o = 1 ; <- i dont want the first name Do $u[$o] = $Users[$o] $o = $o + 1 Until $u[$o] = "" doesnt work :/ You want to put them into a new array? For what? They'll work just fine in the $Users array... $oIE = _IECreate("",0,0) ;Creates a IE 'window' that is totally in the background. The window doesn't come up, the windows taskbar icon doesn't come up, only a process ;The second parameter of _IECreate should be 0, but the third sayswhether it's invisible or not, so 0 is invisible, and 1 is visible.Change it to text or whatever For $i = 1 To UBound($Users) - 1 ;$i = 1 to avoid the first name, and UBound is the size of the array, and since it starts at 0, you do -1, otherwise you'll get an error _IENavitgate($oIE, "http://www.youtube.com/user/" & $Users[$i]) ;Uses the $oIE IE window that was created, that runs in the background, and goes to user page _IELinkClickByText($oIE, "Add as Friend") ;Click the link that says "Add as Friend" Next Hmm, I cant edit my post, wtf? Well here is the full code: .......... The goal is the entire thing should also work in the background Look at the code I posted above, that takes care of the IE window being completely in the background, you won't see its window, its task bar icon, anything. Only the process will be running, so once your script is over, you have to use _IEQuit($oIE) or the process will stay up, and if you keep running the script, it'll eat your memory up. Looking through the code, I couldn't help but find things that you could change... $cLoop = 1 While $cLoop = 1 $p = InputBox($ver, "Wähle deinen iexplore.exe Pfad (sollte korrekt sein)", $ie, "", 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $ff = $p ExitLoop EndIf WEnd To something like: $p = InputBox($ver, "Wähle deinen iexplore.exe Pfad (sollte korrekt sein)", $ie, " M", 333, 150) ;putting " M" for the password char means there won't be a "password char" (like *****) since it's just a space, and the M means it's manditory. You can't have a blank string in there, or it'll have you try again. If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $ff = $p EndIf Shortens it up by 5 lines, and looks a little neater... If $file = -1 Then ;create new file (to better) Opt("SendKeyDelay", 30) Run("notepad.exe"); Open Notepad (create new file) WinWaitActive("Unbenannt - Editor") WinMove("Unbenannt - Editor", "", 0, 0, 1160, 842) Send("^{s}") Send($d & "Youtube Bot\userlist.txt") Sleep(500) Send("{ENTER}") Sleep(500) Send("!{F4}") EndIf Changed to this...: If $file = -1 Then ;create new file (to better) FileWrite($txt, "") ;This will create the file ;) look at FileWrite in the helpfile, and look at the second paragraph under Remarks EndIf Read all the comments on these, most of the explaination is in there. I have to go to an eye exam right now, but I think there was more I wanted to say, so I'll post in probably about 2, maybe 3 hours Edit: Changed this: $mIE = _IECreate("www.youtube.com",0,0) ;open youtube, in an invisible window Got rid of this: $o = 1 Do $u[$o] = $Users[$o] $o = $o + 1 Until $u[$o] = "" Changed this: Do Call("getuser") Sleep(1000) $z = 1 Do If $u[$z] = "" Then $z = 100 Else $txt = $d & "Youtube Bot\userlist.txt" $file = FileOpen($txt, 1) FileWriteLine($file, $u[$z]) FileClose($txt) EndIf Until $z = 100 $un = $un + 40 Until $un >= $iuserget to this: getuser() $txt = $d & "Youtube Bot\userlist.txt" ;this is already defined earlier in the script, so it doesn't need to be here, I don't think FileOpen($txt, 1) ;should be outside the loop, so that it isn't constantly opening and closing the file For $i = 1 To UBound($Users) - 1 ;for loops are very useful, look into them. UBound gets the size of an array, and since $Users starts at 0, not 1, you have to do - 1 FileWriteLine($txt, $Users[$i]) Next FileClose($txt) I didn't get what the purpose of the $un = $un + 40 was, so I left it out. Try those changes, see what you get Edited October 6, 2009 by mistersquirrle We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
arryo Posted October 8, 2009 Author Share Posted October 8, 2009 Like I said, I have trouble with the $Users variable. I get this error: \Youtube Bot\Get Userlist IE.au3 (107) : ==> Variable used without being declared.: For $i = 1 To UBound($Users) - 1 For $i = 1 To UBound(^ ERROR The entire code: expandcollapse popup#include <Inet.au3> #include <String.au3> #include <Array.au3> #include <IE.au3> $ver = "Youtube GetUsers 1.0.au3" $d = @DesktopDir&"\" $ie = @ProgramFilesDir&"\Internet Explorer\iexplore.exe" HotKeySet ( "{Pause}" , "pause" ) $pause = False Func pause () if $pause = false then $pause = true While $pause = true Sleep(1) WEnd Else $pause = false endif Endfunc HotKeySet ( "{Esc}" , "Ende" ) Func Ende () ProcessClose("Debug.exe") Exit EndFunc $q1 = MsgBox(4, $ver, "Start? Hinweis: Exit zum jederzeitigen Beenden des Scripts! Nur für Internet Explorer!") If $q1 = 7 Then MsgBox(0, $ver, "Abgebrochen.") Exit EndIf $p = InputBox($ver, "Wähle deinen iexplore.exe Pfad (sollte korrekt sein)", $ie, " M", 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $ff = $p EndIf $p = InputBox ($ver,"Von welchem User willst du die Userlist bilden? (GetSubscribers)", "wowhobbs","" , 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $getnewu = $p EndIf $p = InputBox ($ver,"Beginnen mit Seite ...", "0","" , 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $page = $p EndIf $p = InputBox ($ver,"Wieviele Users willst du finden? (40,80,120,160 ....), 1040 = max", "1040","" , 333, 150) If @error = 1 Then MsgBox(4096, "Error", "Abgebrochen.") Exit Else $iuserget = $p EndIf $txt = $d&"Youtube Bot\userlist.txt" $file = FileOpen($txt, 0) If $file = -1 Then ;create new file (to better) FileWrite($txt, "") ;This will create the file ;) look at FileWrite in the helpfile, and look at the second paragraph under Remarks EndIf FileClose($txt) Opt("SendKeyDelay", 0) Run("Debug.exe") $mIE = _IECreate ("www.youtube.com", 0 ,0) ;create invisible IE window Local $u[$iuserget] $un = 0 FileOpen($txt, 1) ;should be outside the loop, so that it isn't constantly opening and closing the file Do call ("getuser") ; get the users For $i = 1 To UBound($Users) - 1 ;for loops are very useful, look into them. UBound gets the size of an array, and since $Users starts at 0, not 1, you have to do - 1 FileWriteLine($txt, $Users[$i]) Next $un = $un + 40 ;there are always 40 users on the page --> go to next page Until $un >= $iuserget ;finish FileClose($txt) MsgBox(1, "Finished!", "Finished. Done: "&$iuserget) ProcessClose("Debug.exe") Local $u[50] ; to make sure ALL users are getting in the list Func getuser () _IENavigate ($mIE, "http://www.youtube.com/profile?user="&$getnewu&"&view=subscribers&start="&$un) ;open youtube user _IELoadWait($mIE) $Source = _INetGetSource("http://www.youtube.com/profile?user="&$getnewu&"&view=subscribers&start="&$un) ;Put it the webpage were all these usernames are here $Users = _StringBetween($Source, "/user/", '"') For $i = 0 To UBound($Users) - 1 ;$i = 1 to avoid the first name, and UBound is the size of the array, and since it starts at 0, you do -1, otherwise you'll get an error If UBound($Users) - 1 < $i Then ExitLoop While 1 If StringInStr($Users[$i], $Users[$i + 1], 1) Then _ArrayDelete($Users, $i) If UBound($Users) - 1 <= $i Then ExitLoop Else ExitLoop EndIf WEnd Next EndFunc Link to comment Share on other sites More sharing options...
mistersquirrle Posted October 8, 2009 Share Posted October 8, 2009 Like I said, I have trouble with the $Users variable.I get this error:\Youtube Bot\Get Userlist IE.au3 (107) : ==> Variable used without being declared.:For $i = 1 To UBound($Users) - 1For $i = 1 To UBound(^ ERRORAh, yeah, that's because the $Users variable is being defined and created in a function, and it doesn't like that... At the top of your script just put Global $Users and that should work. Worked just fine for me We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
arryo Posted October 8, 2009 Author Share Posted October 8, 2009 (edited) Ah, yeah, that's because the $Users variable is being defined and created in a function, and it doesn't like that... At the top of your script just put Global $Users and that should work. Worked just fine for meAh, THX!Now it works perfectly!Now I want to do the following:Before it writes the User in the file, it should check if its already in it. When its there, then the script shouldn't write the username. Whats the Function for that? :/Ah perhaps with StringRegExp and FileOpen? I'll try in a few min Edited October 8, 2009 by arryo Link to comment Share on other sites More sharing options...
mistersquirrle Posted October 8, 2009 Share Posted October 8, 2009 if you know how StringRegExp works, then try that. But I was going to suggest something like StringInStr(). I'm going to head out to a bus now, I'll be back in a few hours to post again if you need more help. We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
arryo Posted October 8, 2009 Author Share Posted October 8, 2009 (edited) For $i = 1 To UBound($Users) - 1 ;for loops are very useful, look into them. UBound gets the size of an array, and since $Users starts at 0, not 1, you have to do - 1 if StringRegExp($txt,$Users[$i],0) = 1 Then Else FileWriteLine($txt, $Users[$i]) Endif Next Doesnt work Also, another problem (in a new script): #include <Inet.au3> #include <String.au3> #include <Array.au3> #include <IE.au3> #Include <File.au3> Global $Users ; $startsite = "http://www.youtube.com/user/jzp2009" ; ^this works ; $startsite = "http://www.youtube.com/results?search_query=world+of+warcraft&search_type=&aq=f" ; ^this doesnt work ; $startsite = "http://www.youtube.com/" ; ^this doesnt work either WTF?! $mIE = _IECreate ("www.youtube.com", 0 ,0) ;create invisible IE window _IELoadWait($mIE) $Source = _INetGetSource($startsite) ;site $Users = _StringBetween($Source, "/user/", '"') For $i = 0 To UBound($Users) - 1 ;$i = 1 to avoid the first name, and UBound is the size of the array, and since it starts at 0, you do -1, otherwise you'll get an error If UBound($Users) - 1 < $i Then ExitLoop While 1 If StringInStr($Users[$i], $Users[$i + 1], 1) Then _ArrayDelete($Users, $i) If UBound($Users) - 1 <= $i Then ExitLoop Else ExitLoop EndIf WEnd Next _ArrayDisplay($Users) Why does it only work for the page http://www.youtube.com/user/jzp2009? Error Message: Youtube Bot\test.au3 (26) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: If StringInStr($Users[$i], $Users[$i + 1], 1) Then If StringInStr($Users[$i], ^ ERROR >Exit code: 1 Time: 5.757 --> Perhaps the Page code is to big? Any way to solve that? Edited October 8, 2009 by arryo Link to comment Share on other sites More sharing options...
arryo Posted October 11, 2009 Author Share Posted October 11, 2009 /push I still need help :< Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now