hunte922

[Solved] File Downloading through Browser, but not Script

14 posts in this topic

#1 ·  Posted (edited)

Edit: The solution! Maybe?

 

I need to download an image from a website using AutoIt but the download, when viewed in a text editor, does not appear to be the same as if I had downloaded it from a web browser.

Could anyone help me figure out why this is happening?

I've already tried _INetGetSource, InetGet, _IENavigate, wget, this, and a few .bat and .vbs scripts.

 

Example Code:

#include <Inet.au3>
Local $source = _INetGetSource("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a")
Local $newfile = FileOpen(@ScriptDir & "\test.txt", 2)
FileWrite($newfile, $source)
FileClose($newfile)

Image URL: http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a

Screenshot attached.

Screenshot_60.png

Edited by hunte922

Share this post


Link to post
Share on other sites



#2 ·  Posted

I have same result on both from Autoit and Browser (Text Editor Notepade++)

browser.jpg

text from autoit.png

Share this post


Link to post
Share on other sites

#3 ·  Posted

I got some bizarre results, until i used binary mode flag in fileopen.

$sReturn = BinaryToString(InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8))
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

this works for me anyways

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

9 minutes ago, Muhammad_Awais_Sharif said:

I have same result on both from Autoit and Browser (Text Editor Notepade++)

I just ran the script again and I am still getting the same results. Screenshot attached when viewing the downloaded file in Notepad++.

3 minutes ago, genius257 said:

I got some bizarre results, until i used binary mode flag in fileopen.

That code gives me the same incorrect result.

Screenshot_61.png

Edited by hunte922

Share this post


Link to post
Share on other sites

#5 ·  Posted

Maybe your cache?

$sReturn = InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8+1)
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

All i did was add the flag INET_FORCERELOAD

I've just tested my script on another pc, no problems there either.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

4 minutes ago, genius257 said:

Maybe your cache?

Tried your new code. No changes.

Have you tried it on the latest version of AutoIt?

Edited by hunte922

Share this post


Link to post
Share on other sites

#7 ·  Posted

Just tried

 and it still gave me the same incorrect result.

Share this post


Link to post
Share on other sites

#8 ·  Posted

I was able to replicate your bug. But now it seems i can't undo it ^^'

Maybe it's a result of too many requests i a short time-span to the AmazonS3 server.

It's not the first time I've had an issue like that...

I will try running the script when i wake up and let you know :)

Share this post


Link to post
Share on other sites

#9 ·  Posted

Found something that works. Let's hope it stays that way...

RunWait('powershell.exe & { Invoke-WebRequest -Uri "http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a" -OutFile "text.txt" }')

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

Hello. What's wrong with this way?

InetGet("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a","test.txt")

Saludos

Share this post


Link to post
Share on other sites

#11 ·  Posted

So i tried again just now, and it works fine again. The error seems to be related to too many server request within a time-frame. So i would suggest checking the downloaded file for a valid image-format and if not wait at least 1hour before trying again.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Please try this

HttpSetUserAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)")
$sReturn = BinaryToString(InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8))
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

Edit
10 times downloaded and still working :)

Edited by mikell

Share this post


Link to post
Share on other sites

#13 ·  Posted

On 6/10/2016 at 6:27 PM, mikell said:

10 times downloaded and still working

I ran my test codes at least 100times in under 1 hour before it started getting weird with the results.

Share this post


Link to post
Share on other sites

#14 ·  Posted

On 10/6/2016 at 11:27 AM, mikell said:

Please try this

HttpSetUserAgent("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)")
$sReturn = BinaryToString(InetRead("http://c0.rbxcdn.com/0db36a45eae4838667ae9a46ba0c082a", 8))
$hFile = FileOpen("test.png", 2+16)
FileWrite($hFile, $sReturn)
FileClose($hFile)

Edit
10 times downloaded and still working :)

 

9 minutes ago, genius257 said:

I ran my test codes at least 100times in under 1 hour before it started getting weird with the results.

I got it to work. The link to the solution is in the original post.

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

    • TommyDDR
      GUICtrlSetResizing and hidden window
      By TommyDDR
      Hi,
      I have to set a resizing mode to differents controls in a hidden gui, that gui is initialised (hidden) and resized by a WinMove.
      But when i show it, control are not resized where thez should.
      There is a simple code that reproduce the problem.
      Same gui, same content, one displayed then moved, the other moved then displayed :
      #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $gui[2] Global $labels[2] Global $taille[2] = [200, 100] For $i = 0 To UBound($gui, 1) - 1 $gui[$i] = GUICreate($i, $taille[0], $taille[1], $i * ($taille[0]+100) + 500, (@DesktopHeight-$taille[1])/2) GUISetOnEvent($GUI_EVENT_CLOSE, "quit", $gui) $labels[$i] = GUICtrlCreateLabel("Test resizing...", $taille[0]-105, $taille[1]-25, 100, 20) GUICtrlSetBkColor($labels[$i], 0xE0E0E0) GUICtrlSetResizing($labels[$i], BitOR($GUI_DOCKRIGHT, $GUI_DOCKBOTTOM, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT)) Next GUISetState(@SW_SHOW, $gui[0]) For $i = 0 To UBound($gui, 1) - 1 WinMove($gui[$i], "", Default, Default, $taille[0]+100, $taille[1]+100) Next GUISetState(@SW_SHOW, $gui[1]) While(True) Sleep(10) WEnd Func quit() Exit EndFunc Is that a bug or do miss i something ?
      EDIT : This bug disapear if gui is shown at lease one time (even if hide then)
    • echoAwoo
      Looped Array Out of Range (_Excel_RangeFind output)
      By echoAwoo
      SOLVED
      Basically, my script needed a conditional assignment to a variable. It needed to check if the size of the array was valid before assigning any value to the variable.
       
       


      So I've got a data entry task that I've been trying to automate. I actually have the script running, it cycles, draws it's necessary arrays, etc. But it will only cycle up to count #22, 23+ do not work.
      THE GIST
      I have two excel documents that I draw the data from. $aWO array has values from one of these documents. The instructions to draw these are under _at_wo().
      This function feeds into another function to compare a derived value from the first file and request it's corresponding value. In order to do this, I used _Excel_RangeFind() (had to comment out the Cell Name and Cell Comment aspects of that function in order for it to work at all.) Then I pull the address information from array $aTracking[0][2], swap the column from A to B, and it works beautifully. 
      Then cycle 23 happens, and then $aTracking[0][2] reports as out of range. Why? 
       
      Here's the code. Error reported from line #70. This array call works on loops 1-22 ($iCount value 0-21)
      http://pastebin.com/Bd5v6Dbc
    • Simpel
      [Solved] SciTE no functions working
      By Simpel
      Hi,
      I updated to the last version. Since then a lot of functions are not working.  For instance expanding abbreviation. My au3abbrev.properties are correct and abbrev.properties are including both import lines. The abbreviation is red but won't expand. Neither with space nor Ctrl+B.
      Debug to msgbox and console not working, list functions, jump to function, open include too.
      SciTE Jump works. Block and box comment too.
      I have the feeling all functions especially for autoit are not working.
      Any help? Regards, Conrad
    • Simpel
      Again WinHTTP and Proxy
      By Simpel
      Hi there.
      I'm testing this code:
      #include "WinHttp.au3" ; http://www.w3schools.com/php/demo_form_validation_escapechar.php $sUserName = "SomeUserName" $sEmail = "some.email@something.com" $sDomain = "www.w3schools.com" $sPage = "/php/demo_form_validation_escapechar.php" ; Data to send $sAdditionalData = "name=" & $sUserName & "&email=" & $sEmail ; Initialize and get session handle $hOpen = _WinHttpOpen("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hOpen = ' & $hOpen & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ; Get connection handle $hConnect = _WinHttpConnect($hOpen, $sDomain) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hConnect = ' & $hConnect & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ; Make a request $hRequest = _WinHttpOpenRequest($hConnect, "POST", $sPage) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hRequest = ' & $hRequest & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ; Send it. Specify additional data to send too. This is required by the Google API: $hSendRequest = _WinHttpSendRequest($hRequest, "Content-Type: application/x-www-form-urlencoded", $sAdditionalData) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hSendRequest = ' & $hSendRequest & @CRLF & '>Error code: ' & @error & @TAB & "@extended: " & @extended & @CRLF) ;### Debug Console ; Wait for the response $hReceiveResponse = _WinHttpReceiveResponse($hRequest) ; See what's returned Dim $sReturned If _WinHttpQueryDataAvailable($hRequest) Then ; if there is data Do $sReturned &= _WinHttpReadData($hRequest) Until @error EndIf ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; See what's returned ConsoleWrite("Returned: " & $sReturned & @CRLF) But sending a request fails.
      Console outputs this:
      >Running:(3.3.12.0) ... --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop @@ Debug(14) : $hOpen = 0x00000000007DF540 >Error code: 0 @@ Debug(18) : $hConnect = 0x00000000008271C0 >Error code: 0 @@ Debug(22) : $hRequest = 0x00000000008B88E0 >Error code: 0 @@ Debug(26) : $hSendRequest = 0 >Error code: 1 @extended: 0 Returned: +>17:00:18 AutoIt3.exe ended.rc:0 +>17:00:18 AutoIt3Wrapper Finished. >Exit code: 0    Time: 0.6003 I'm testing it at work. There, we always have to identify at a proxy to be allowed to go to internet. But requests via inet.au3 will work. Maybe our firewall will block the request?
      Any ideas? I don't have any possibilities to test at home, because of OSX.
       
      Regards, Conrad
    • yhu420
      [SOLVED]Count duplicates in an array
      By yhu420
      Hello everyone,
      I just have a beginner question: is there a way to count duplicates in an array? If you don't see what I mean, here is an example of what I mean:
      $arr[5] = ['a', 'a', 'b', 'b', 'c'] ; the array countDuplicates($arr); Representing the data in a bidimensionnal array, this would return: #cs ['a'][2] ['b'][2] ['c'][1] Of course this is a bit messy, but that's just for you to get the idea #ce I'm trying to achieve this to check whether yes or no an array has more or same amount of occurrences of a character than another array.
      Am I doing this the right way?
      Does such a function exist?
      Thanks for everything