Jump to content

[UNSOLVED] Writing [SUCCESS] after each line


Recommended Posts

4 hours ago, mikell said:

My (personal) feeling about your logic is that you should try something like this

#include <String.au3>
#include <Array.au3>
#Include <File.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Local $aInput
_FileReadToArray("email.txt", $aInput)  ; read the list of names to array

For $i = 1 To $aInput[0]   ; for each name
    $oHTTP.Open("GET", "https:///" & $aInput[$i], 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", "")
    $oHTTP.SetRequestHeader("Referer", "https:///")
    $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
    $oHTTP.Send
    $oReceived = $oHTTP.ResponseText
    $oStatusCode = $oHTTP.Status
    If $oStatusCode = 404 Then $aInput[$i] &= " [SUCCESS]"  ; append to the address
Next

$oHTTP = 0
_FileWriteFromArray("checked.txt", $aInput, 1)  ; rewrite the array to file

 

Thank you I got it working.
 

$oHTTP.Send
    $oReceived = $oHTTP.ResponseText
    $oStatusCode = $oHTTP.Status

    If $oStatusCode = 404 Then
        $aInput[$i] &= " [SUCCESS]"  ; append to the address
        _FileWriteFromArray("checked.txt", $aInput, 1)  ; rewrite the array to file

    EndIf
Next
Sleep(3000)

This makes it work as intended!
Thanks a lot everyone for the hard working & help!

Link to comment
Share on other sites

14 hours ago, mikell said:

My (personal) feeling about your logic is that you should try something like this

#include <String.au3>
#include <Array.au3>
#Include <File.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Local $aInput
_FileReadToArray("email.txt", $aInput)  ; read the list of names to array

For $i = 1 To $aInput[0]   ; for each name
    $oHTTP.Open("GET", "https:///" & $aInput[$i], 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", "")
    $oHTTP.SetRequestHeader("Referer", "https:///")
    $oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
    $oHTTP.Send
    $oReceived = $oHTTP.ResponseText
    $oStatusCode = $oHTTP.Status
    If $oStatusCode = 404 Then $aInput[$i] &= " [SUCCESS]"  ; append to the address
Next

$oHTTP = 0
_FileWriteFromArray("checked.txt", $aInput, 1)  ; rewrite the array to file

 

If I were to delete all other response codes than 404
so I only have a checked.txt in the end with $aInput [SUCCESS]

Would I do something like
If $oStatusCode <> 404 Then
REMOVE $aInput[$i]

that is how I need my code to function, I'll look around see if I can fix it myself.
but any help is appreciated.

Link to comment
Share on other sites

Instead of _ArrayDelete'ing I suggest an other approach : create an array $aOutput , populate it with the wanted results and then save it to checked.txt

#include <String.au3>
#include <Array.au3>
#Include <File.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Local $aInput
_FileReadToArray("email.txt", $aInput) 

Local $aOutput[$aInput[0]], $n   ;<<<<<<<<<<< here it is
For $i = 1 To $aInput[0]   ; for each name
    $oHTTP.Open("GET", "https:///" & $aInput[$i], False)
    ; etc
    ; ....
    $oStatusCode = $oHTTP.Status
    If $oStatusCode = 404 Then 
         $aOutput[$n] = $aInput[$i] & " [SUCCESS]"  ;<<<<<<<
         $n += 1     ;<<<<<<<<
    EndIf
Next

Redim $aOutput[$n]  ;<<<<<<<
_FileWriteFromArray("checked.txt", $aOutput, 1)  
$oHTTP = 0

 

Link to comment
Share on other sites

12 hours ago, mikell said:

Instead of _ArrayDelete'ing I suggest an other approach : create an array $aOutput , populate it with the wanted results and then save it to checked.txt

#include <String.au3>
#include <Array.au3>
#Include <File.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Local $aInput
_FileReadToArray("email.txt", $aInput) 

Local $aOutput[$aInput[0]], $n   ;<<<<<<<<<<< here it is
For $i = 1 To $aInput[0]   ; for each name
    $oHTTP.Open("GET", "https:///" & $aInput[$i], False)
    ; etc
    ; ....
    $oStatusCode = $oHTTP.Status
    If $oStatusCode = 404 Then 
         $aOutput[$n] = $aInput[$i] & " [SUCCESS]"  ;<<<<<<<
         $n += 1     ;<<<<<<<<
    EndIf
Next

Redim $aOutput[$n]  ;<<<<<<<
_FileWriteFromArray("checked.txt", $aOutput, 1)  
$oHTTP = 0

 

That does not seem to do the trick?
I receive nothing in checked.txt

I thought it would be easier deleting it all using some string function?
If string contains SUCCESS skip
or if status code = 404 write SUCCESS & Skip
Then write $aInput & Success to new file such as chekced.txt

Right now its working for me writing SUCCESS after each line that responds with 404.

However deleting the appropriate lines/results is not possible to me as of yet.

Link to comment
Share on other sites

2 hours ago, mikell said:

Did you replace in my snippet the "etc" by the omitted lines ?

Yes I edited everything to fit your code.
However after running it does not state errors and it does not update the file with the new values.
 

#include <String.au3>
#include <Array.au3>
#Include <File.au3>

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
Local $aInput
_FileReadToArray("email.txt", $aInput)

Local $aOutput[$aInput[0]], $n   ;<<<<<<<<<<< here it is
For $i = 1 To $aInput[0]   ; for each name
    $oHTTP.Open("GET", "" & $aInput[$i], False)
   $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", "")
$oHTTP.SetRequestHeader("Referer", "")
$oHTTP.SetRequestHeader("X-Requested-With", "XMLHttpRequest")
; Header data <

; Performing the Request
$oHTTP.Send
;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
    $oStatusCode = $oHTTP.Status
    If $oStatusCode = 404 Then
         $aOutput[$n] = $aInput[$i] & " [SUCCESS]"  ;<<<<<<<
         $n += 1     ;<<<<<<<<
    EndIf
Next

Redim $aOutput[$n]  ;<<<<<<<
_FileWriteFromArray("checked.txt", $aOutput, 1)

Excuse me if I messed anything up and didn't notice.
Thanks in advance

Link to comment
Share on other sites

It should work, I suggest a debug by putting some ConsoleWrite and _ArrayDisplay in the code
Here is a sample code to illustrate the concept

#include <String.au3>
#include <Array.au3>
#Include <File.au3>

; build test file
Local $txt
For $i = 0 to 30
   $txt &= StringFormat("%02i", $i) & @crlf
Next
FileWrite("test.txt", $txt)

; read test.txt file to array
Local $aInput
_FileReadToArray("test.txt", $aInput) 
_ArrayDisplay($aInput, "$aInput")

; declare array for output and variable for incrementation
Local $aOutput[$aInput[0]], $n = 0 

; check lines
For $i = 1 To $aInput[0]  
    If StringInStr($aInput[$i], "4") Then   ; condition for output
         $aOutput[$n] = $aInput[$i] & " [SUCCESS]"
         $n += 1   
    EndIf
Next

Redim $aOutput[$n]
_ArrayDisplay($aOutput, "$aOutput")
  
_FileWriteFromArray("checked.txt", $aOutput, 0)

 

Edited by mikell
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...