Jump to content
RyukShini

Array Loop - I am stuck

Recommended Posts

RyukShini

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

 

Share this post


Link to post
Share on other sites
RyukShini

I would really appreciate some help.
if it is my grammar and/or if I explained myself poorly, please let me know.

Share this post


Link to post
Share on other sites
Jos

@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 Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Jfish

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

Share this post


Link to post
Share on other sites
RyukShini
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.

Share this post


Link to post
Share on other sites
RyukShini
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

Share this post


Link to post
Share on other sites
Jfish

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.


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

Share this post


Link to post
Share on other sites
RyukShini
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.

Share this post


Link to post
Share on other sites
RyukShini
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.

Share this post


Link to post
Share on other sites
Jfish

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

Share this post


Link to post
Share on other sites
Melba23

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

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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

  • Similar Content

    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to write a script that moves copies excel cells into an array. I'll than manipulate the values and send array into another program. 
      I don't want range to be specific to a workbook, or sheet, or set of cells.
      I want user to be able to highlight desired cells and to copy either normally ("Ctrl+C") or by a hotkey ("Alt+C"). 
      Could someone help me with this?
      Thank you,
      I've tried to write the framework: (edited)
      #include <MsgBoxConstants.au3> #include <Array.au3> #include <Excel.au3> HotKeySet("!v", "Pastedata") While True Sleep(1000) WEnd func Makearray() local $bArray ;User has cells already copied ;Convert clipboard into an array ;I don;t know how excel stores data to clipboard so don;t know how to bring it into array _Arraydisplay($bArray) MsgBox(0,0,$bArray) return $bArray endfunc func Pastedata() Local $aArray MsgBox(0,0,"wait",1) ;make array based on assumption user has already copied a range to clipboard $aArray = Makearray() ;paste code ;don;t worry about this I got the rest endfunc  
×