[Tutor] HTTP file download

Kent Johnson kent37 at tds.net
Wed Mar 14 12:35:55 CET 2007


Ronaldo wrote:
>   Hi, Jean
> 
>   I've alredy tried this, but it seems that this kind of code just works
> when "file" in the url (http://www.somesite.com/file) is an html file.
> The thing is that "file" in this case is a text file. For example: if I
> try to download the file using a web browser, it asks me for a directory
> to save the file.
>   Do you have any other idea?

The code below should work fine for a text file. Can you show us the 
code that fails and tell us how it fails? If you can include the URL you 
are trying to download that would also help.

Kent
> 
>   Thanks.
> 
> Jean-Philippe Durand wrote:
>> Hello Ronaldo,
>> Try this :
>> import urllib                                       
>>
>> mysock = urllib.urlopen("http://www.somesite.com/file") 
>>
>> htmlSource = mysock.read()                            
>> mysock.close()                                        
>>
>> print htmlSource     
>> Regards.
>> Jean-Philippe DURAND


More information about the Tutor mailing list