Jump to content

inetget doesn't save file but no error in inetgetinfo


Recommended Posts

This is unrelated to the topic I posted earlier today.

I'm using inetget to retrieve a file online. sometimes this works, sometimes it doesn''t work but inetgetinfo gives a non-zero error number. Atleast I have an idea about what went wrong in that case.

However, the most confusing of all is I sometimes get no error message but the file does not appear in my target directory.

my code is pasted below:

$i=99999
$keyword = "amazon"
$hDownload = InetGet("http://www.google.com/trends/fetchComponent?q=" & $keyword & "&geo=US&cid=TIMESERIES_GRAPH_0&export=3&date=today%203-m&cmpt=q",  @DesktopDir  & "data_" & $i & ".txt",0,1)

$inetgettime=0

   Do
      Sleep(250)
      $inetgettime=$inetgettime+0.25
      If $inetgettime>10 Then
         $timedout=1
         InetClose($hDownload)
         ConsoleWrite("timed out waiting for download " & $inetgettime & @CRLF)
         $timedout=1
         ExitLoop
      EndIf
   
   Until InetGetInfo($hDownload, 2) ; Check if the download is complete.

$err = InetGetInfo($hDownload)

ConsoleWrite("internet error = " & $err[4] & @CRLF)

When the strange non-saving while $err=0 behaviour occurs, it is too fast for my 10 second timeout loop.

The script takes about 0.9 seconds to run when the behaviour I described above is shown.

Does anybody have an idea as to the cause of this?

Link to comment
Share on other sites

adamchapman,

Your output file is not specified correctly.  See comments in code.

$i=99999
$keyword = "amazon"

; try adding a slash before the filename as below

$hDownload = InetGet("http://www.google.com/trends/fetchComponent?q=" & $keyword & "&geo=US&cid=TIMESERIES_GRAPH_0&export=3&date=today%203-m&cmpt=q",  @DesktopDir  & "\data_" & $i & ".txt",0,1)

$inetgettime=0

   Do

      Sleep(250)
      $inetgettime=$inetgettime+0.25
      If $inetgettime>10 Then
         $timedout=1
         InetClose($hDownload)
         ConsoleWrite("timed out waiting for download " & $inetgettime & @CRLF)
         $timedout=1
         ExitLoop
      EndIf

   Until InetGetInfo($hDownload, 2) ; Check if the download is complete.

$err = InetGetInfo($hDownload)

ConsoleWrite("internet error = " & $err[4] & @CRLF)

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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