Jump to content

Array Loop - I am stuck


Recommended Posts

My problem is that I wish my script to make a new received.html each run.
I have looped everything and I got it to read my file as a loop in a msgbox.

Right now I have stored some emails in email.txt
All those emails is post data "$postcred"
$oHTTP.Open("GET"), "" & $postcred, False)

Later on I read the response and save the source/body of the site.
It runs fine, however it only picks up the first line and I need it to run untill all lines are finished.
Then for each file/request it should create a new .html file.

 

Thanks in advance

 

#include <String.au3>
#include <Array.au3>
#Include <File.au3>
$oldreadamount = "Page Not"

While 1 ; <--- start a loop to keep prog going

Local $emails = "C:\Users\Gr3ndel\Desktop\autoit\Instagram\email.txt" ;sets file path
Local $ArrayEmail[57] ;declares array

_FileReadToArray($emails, $ArrayEmail) ;converts file to array
For $i = 1 to UBound($ArrayEmail) -1)
$postcred = (0,'',$ArrayEmail[$i])
    Next


; The data to be sent
$sPD = ''

; Post data/User information - You gotta update csrftoken if it reports errors / 404 codes

; Creating the object
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("GET", "" & $postcred, False) ; Post url
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") ; Header data >
$oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
$oHTTP.SetRequestHeader("User-Agent", "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.52 YaBrowser/15.12.2490.3614 (beta) Yowser/2.5 Safari/537.36")
$oHTTP.SetRequestHeader("X-CSRFToken", "472f9ab4b4cfe2ab9160648a2a957fcb")
$oHTTP.SetRequestHeader("Referer", "")
$oHTTP.SetRequestHeader("Cookie", "")
$oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
; Header data <
; Performing the Request
$oHTTP.Send($sPD)
;Sends the post data with the given details

;Download the body response if any, and get the server status response code.
$oReceived = $oHTTP.ResponseText
$oStatusCode = $oHTTP.Status

If $oStatusCode <> 200 then
 MsgBox(4096, "Response code", $oStatusCode)
EndIf

; Saves the body response regardless of the Response code
 $file = FileOpen("Received1.html", 2) ; The value of 2 overwrites the file if it already exists
  FileWrite($file, $oReceived)
 FileClose($file)
 $read = FileRead("Received1.html") ;read file
 $Datastring = ('<title>')
$newreadamount = _StringBetween($read,$Datastring, "</title>") ;read title from file
If $oldreadamount = ""  Then
 MsgBox($newreadamount, "")
EndIf

Sleep(5000) ; wait 2 minutes before looking again
$oldreadamount = $newreadamount[0]

WEnd

 

Link to comment
Share on other sites

  • Developers

@RyukShini,

Please do not bump your own threads within 24 hours.
Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare.  You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You realize there is no way to escape your while loop ... so that is an infinite loop?  Instead, consider using only the for loop and having it finish when all the rows of the array are completed.  At present, that outer loop is making all the stuff inside it repeat over and over again.  However, the result is that it will create an array and probably send only the last element in the array (because you looped them all and then it finished and $postcred had the last value in the loop).  You have no code to send the other 56 elements.  In summary, try removing the outer while loop and moving your logic inside the for loop.

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

19 minutes ago, Jos said:

@RyukShini,

Please do not bump your own threads within 24 hours.
Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare.  You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.

Jos

I am sorry, I will remember that of course.

Link to comment
Share on other sites

13 minutes ago, Jfish said:

You realize there is no way to escape your while loop ... so that is an infinite loop?  Instead, consider using only the for loop and having it finish when all the rows of the array are completed.  At present, that outer loop is making all the stuff inside it repeat over and over again.  However, the result is that it will create an array and probably send only the last element in the array (because you looped them all and then it finished and $postcred had the last value in the loop).  You have no code to send the other 56 elements.  In summary, try removing the outer while loop and moving your logic inside the for loop.

I know that it is not working and I seem to understand why.
but I am struggling with configuring my script.

I have looked around different places.
but I can't seem to get it to work.
I want each line from file inserted here "$line"
 

$oHTTP.Open("GET", "" & $line, False) ; Post url

I know how to get them there without looping and counting each line etc.
but getting it to read from line 1 and to the end of the .txt and afterwards save the body response in .html each time it inserts a new username/loops.

I am not sure if you can give me a clue or something to work with?

Thanks in advance

Link to comment
Share on other sites

8 minutes ago, Jfish said:

Please re-read my post.  You need to have that code in your FOR loop not your WHILE loop.  You don't need the WHILE loop.  I already explained why I think it is not working and how to fix it.

Alright thank you.
I will take another look on it from your instructions.

Link to comment
Share on other sites

14 minutes ago, Jfish said:

Please re-read my post.  You need to have that code in your FOR loop not your WHILE loop.  You don't need the WHILE loop.  I already explained why I think it is not working and how to fix it.

For $i = 1 to UBound($ArrayEmail) -1
$oHTTP.Open("GET", "urlhere" & $ArrayEmail[$i], False) ; Post url
    Next

This does not give me errors.
It works as expected more  or less.
However instead of using the value from each line.
It reads it all the way and inserts the last line of the file.
I feel frustrated because everything has worked out well so far and now I am stuck.

Link to comment
Share on other sites

Please post ALL you revised code.  Also, I would add some error checking.  I would recommend using _arrayDisplay to see what the array looks like.  Make sure it contains the data in the format you expect.

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

  • Moderators

RyukShini,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - we know what we wrote and it just pads the thread unnecessarily. Thanks for your cooperation.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...