Jump to content
hunte922

[Solved] File Downloading through Browser, but not Script

Recommended Posts

hunte922

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
Muhammad_Awais_Sharif

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
genius257

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

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

Just tried

 and it still gave me the same incorrect result.

Share this post


Link to post
Share on other sites
genius257

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
hunte922

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
Danyfirex

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
genius257

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
mikell

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

    • CodingMonkey81
      By CodingMonkey81
      All,
      I'm working on automating the update process for a piece of software that we use at my company. The installer file always contains the version number as a part of the file name (eg InstallFile_9342.msi) and the numbers always change with every update.
      How do I use AutoIt to run the program? I know I can't use a wildcard in place of the numbers when using the "Run" command. 
      I tried 
      Local $aArray = _FileListToArray("C:\path\to\file", "InstallFile_*.msi", 0, 1) Run("$aArray") and I also tried
      Local $bInstall = FileFindFirstFile("InstallFile_*.msi") Run("$bInstall") and neither worked. 
      Can someone please point me in the right direction? I've done some searching on the forum and haven't found anyone in a similar situation before.
      Thanks!
    • RHolmes
      By RHolmes
      I have a program that has a control that changes color a few seconds into running. So ideally, I would poll this to tell when an event has occurred. 
      I can't seem to retrieve the correct color value for a control. It always seems to return white indicating that its selecting somewhere else in the window.
      In the PixelGetColor call I'm adding half the width to the x value and subtracting half the height to the y value  in order to get the center of the control. (assuming the coords returned by ControlGetPos are top left - which i can't be sure of) But I've also tried without modifying the x/y and with changing the PixelCoordMode option to 2. Maybe I'm making a silly mistake and can't see it? Any help would be appreciated.
      Code is below:
      Opt("PixelCoordMode", 0)
      FileChangeDir( "C:\Where\My\File\Is" );
      Run( "MyProgram.exe" )
      Local $hClient = WinWaitActive( $CLIENT_TITLE, "", 10 )
      Local $systemIndicatorClassNN= "[CLASS:Qt5QWindowIcon; INSTANCE:99]"
      Local $hSystemIndicator = ControlGetHandle ( $hClient, "", $systemIndicatorClassNN)
      Local $xywh = ControlGetPos ( $hClient, "", $hSystemIndicator )
      For $i = 10 To 1 Step -1
            $color = PixelGetColor ( $xywh[0] + ($xywh[2]/2), $xywh[1] - ($xywh[3]/2), $hClient )
            LogToFile( $color )
            Sleep( 2000 )
      Next
    • VAN0
      By VAN0
      Hello.
      I have a program XX that asks for user confirmation on exit, which hangs the system reboot/shutdown process until I confirm. So I decided create a autoit script that would automatically close that dialog and let the system reboot/shutdown.
      The problem I'm facing is that my scripts now exits before the XX.
      Is there a way delay script exit until the XX is closed but only when system is rebooting/shutting down?
       
      Thank you.
    • Simpel
      By Simpel
      Hi, I created a gui with date field but formatted as time in HH:mm. It always shows "now-time". Even if I try to set it with GUICtrlSetData.
      #include <DateTimeConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT) ; to select a specific default format Local $sStyle = "HH:mm" ; Just display hours and minutes <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle) ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUICtrlSetData($idDate, "00:00") ConsoleWrite(GUICtrlRead($idDate) & @CRLF) GUISetState(@SW_SHOW) ; Loop until the user exits. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate)) EndFunc ;==>Example How can I set the time field with another time and how can this field be set blank?
      Regards, Conrad
    • TommyDDR
      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)
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.