RyukShini

Array Loop - I am stuck

11 posts in this topic

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



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

@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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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

#10 ·  Posted (edited)

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

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

    • rootx
      By rootx
      I write this script to compare to array, well Do you have a better way to do it?
      #include <Constants.au3> #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> $a = FileSelectFolder("seleziona cartella A",@ScriptDir) $fold_A = _FileListToArrayRec($a,"*",2,1,0,1) $b = FileSelectFolder("seleziona cartella B",@ScriptDir) $fold_B = _FileListToArrayRec($b,"*",2,1,0,1) $tota = UBound($fold_A)-1 $totb = UBound($fold_B)-1 If $tota > $totb Then findx($fold_A,$fold_B) Else findx($fold_B,$fold_A) EndIf Func findx($min,$max) For $i = 0 To UBound($min)-1 $found = _ArraySearch($max, $min[$i]) If $found = -1 Then ConsoleWrite($min[$i]&@CRLF) EndIf Next EndFunc  
    • Jibberish
      By Jibberish
      I am trying to add data to an array and I keep getting the error "Subscript used on non-accessible variable ".
      #include <array.au3> ; Includes, etc ~ ~ ~ Local $aOptionsArray[3] $aOptionsArray = CheckboxesAndRadioButtons() _ArrayDisplay($aOptionsArray) Func CheckboxesAndRadioButtons() ; Create Checkboxes and Radio Buttons and read the results ~ ~ ~ ; Radio Buttons to Array ; $aOptions[0] = $bTestSelectForever ; $aOptions[1] = $bTestSelect3Times ; $aOptions[2] = $bTestSelectOnce If $bSelect1 = 1 Then $aOptions[0] = "True" Else $aOptions[0] = "False" <<< This is where the error occurs. EndIf If $bSelect2 = 1 Then $aOptions[1] = "True" Else $aOptions[1] = "False" EndIf If $bSelect3 = 1 Then $aOptions[2] = "True" Else $aOptions[2] = "False" EndIf Return $aOptions EndFunc Is putting data into an array while in a If - Then - Else illegal?
    • Nareshm
      By Nareshm
      How to repeat my script when my control class does not match ?
       
      My Script : winActivate ( " PS :: Version - 2.2.0.0  - [PS Bill]")                   ControlClick ( "PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]")                   ControlSend(" PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]", "{enter}")                   WinActive ("Verification Number Entry ::")                   ControlClick("Next >", "","[NAME:btnNext]") ;if   >>>> Control <<<<  does not match repeat my script, ;if match exit script  

      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
    • anoig
      By anoig
      Hi all, 

      First, I want to give a huge shout-out to the community. I'm completely self-taught, and have never had to actually ask a question before because the forum is that good at answering questions and explaining things. However, I'm kind of stumped here, and I've been stuck on this problem for almost a full day.

      I'm working on a script to populate drafts of deeds at work. I have the main GUI and  a function (ctrl($n) and read()) for adding fields to find and data to replace it with to an array for later use with _word_docfindreplace. All of that works. However, due to the way I have the forms set up, I need to create additional fields and info based on the data that's there. Specifically, if there's only one buyer, I need to add the field [Buyer1&2] and the data in $aArray_Base for [Buyer 1]. I also need to add a field [Buyer 2] and have a blank data set in the next column over in the array, and I need to do the same for the Seller. To this end, the function parties() sets boolean variables $2buyers and $2sellers accordingly. Then, I have buyers() and sellers() to populate the data. 

      The problem that I'm running into is that each function works... when ONLY the buyer 1 name field is filled, and when ONLY the seller 1 field is filled.

      So if I fill Buyer 1 Name and save it, the data is populated correctly. But when I fill Buyer 1 and Seller 1 name, only the buyer 1 data populates correctly. Worse, when I fill several fields, neither populate correctly. I have no idea why this happens. I've added messageboxes to debug throughout the entire process and can't pinpoint what's causing the issue. The entire script is below. The function(s) in question are buyers() and sellers(). Only Sellers() has messageboxes throughout.

      Can someone help walk me through what might be causing this and help me find a solution? Thanks a ton in advance, and sorry for the wall of text.
      -Anoig
       
    • SkysLastChance
      By SkysLastChance
      I am not sure why I am getting the this error on my second pass of the code.
      1 - $oWorkbook is not an object or not a workbook object
      Any help or advice on my code appreciated. 
      #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") Global $vRow = 2 If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole) $Clip = _ArrayToClip($oFind,"",0,0,"",2,2) Send("{ScrollLock Off}") $hWnd = WinWait("[CLASS:XLMAIN]") ControlSend($hWnd, "", "", ("^g")) WinWait("[CLASS:bosa_sdm_XL9]") ; Go To ControlSend($hWnd, "", "", ("^v")) ControlSend($hWnd, "", "", ("{Enter}")) ControlSend($hWnD, "", "", "{Down " & $vRow & "}") Do $oTime = _Excel_RangeRead ($oExcel2,"Untitled","B2",3) If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(0,"Test",$oTime) IF $oTime = "7:10:00 AM" Then $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3) $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3) ControlSend($hWnd, "", "", $oCalls1) ControlSend($hWnd, "", "", ("{RIGHT}")) ControlSend($hWnd, "", "", $oCalls2) $vRow = $vRow + 1 ContinueLoop Else $vRow = $vRow + 1 EndIf Until $vRow = 4 1.xlsm
      2.xlsx