Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   how to download internet files by python ? (http://www.velocityreviews.com/forums/t956292-how-to-download-internet-files-by-python.html)

iMath 01-08-2013 04:19 AM

how to download internet files by python ?
 
for example ,if I want to download this file ,how to implement the download functionality by python ?

http://down.51voa.com/201208/se-ed-f...ds-16aug12.mp3

as for download speed ,of course ,the fast ,the better ,so how to implement it ?

It would be better to show me an example :) thanks !!!

Cameron Simpson 01-08-2013 04:44 AM

Re: how to download internet files by python ?
 
On 07Jan2013 20:19, iMath <redstone-cold@163.com> wrote:
| for example ,if I want to download this file ,how to implement the download functionality by python ?
|
| http://down.51voa.com/201208/se-ed-f...ds-16aug12.mp3
|
| as for download speed ,of course ,the fast ,the better ,so how to implement it ?
| It would be better to show me an example :) thanks !!!

Look at urllib2.
--
Cameron Simpson <cs@zip.com.au>

If God had intended Man to fly, He would have given him more money.
- Jeff Cauhape, cauhape@TWG.COM

Rodrick Brown 01-08-2013 05:00 AM

Re: how to download internet files by python ?
 
On Mon, Jan 7, 2013 at 11:19 PM, iMath <redstone-cold@163.com> wrote:

> for example ,if I want to download this file ,how to implement the
> download functionality by python ?
>
> http://down.51voa.com/201208/se-ed-f...ds-16aug12.mp3
>
> as for download speed ,of course ,the fast ,the better ,so how to
> implement it ?
>
> It would be better to show me an example :) thanks !!!
> --
> http://mail.python.org/mailman/listinfo/python-list
>


#!/usr/bin/python
import urllib2
if __name__ == '__main__':
fileurl='
http://down.51voa.com/201208/se-ed-f...ds-16aug12.mp3'

mp3file = urllib2.urlopen(fileurl)
with open('outfile.mp3','wb') as output:
output.write(mp3file.read())


Roy Smith 01-08-2013 05:04 AM

Re: how to download internet files by python ?
 
In article <mailman.259.1357620254.2939.python-list@python.org>,
Cameron Simpson <cs@zip.com.au> wrote:

> On 07Jan2013 20:19, iMath <redstone-cold@163.com> wrote:
> | for example ,if I want to download this file ,how to implement the download
> | functionality by python ?
> |
> | http://down.51voa.com/201208/se-ed-f...ds-16aug12.mp3
> |
> | as for download speed ,of course ,the fast ,the better ,so how to
> | implement it ?
> | It would be better to show me an example :) thanks !!!
>
> Look at urllib2.


Even better, look at requests
(http://docs.python-requests.org/en/latest/). There's nothing you can
do with requests that you can't do with urllib2, but the interface is a
whole lot easier to work with.

MRAB 01-08-2013 03:19 PM

Re: how to download internet files by python ?
 
On 2013-01-08 05:00, Rodrick Brown wrote:
> On Mon, Jan 7, 2013 at 11:19 PM, iMath <redstone-cold@163.com
> <mailto:redstone-cold@163.com>> wrote:
>
> for example ,if I want to download this file ,how to implement the
> download functionality by python ?
>
> http://down.51voa.com/201208/se-ed-f...ds-16aug12.mp3
>
> as for download speed ,of course ,the fast ,the better ,so how to
> implement it ?
>
> It would be better to show me an example :) thanks !!!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
> #!/usr/bin/python
> import urllib2
> if __name__ == '__main__':
>
> fileurl='http://down.51voa.com/201208/se-ed-foreign-students-friends-16aug12.mp3'
>
> mp3file = urllib2.urlopen(fileurl)
> with open('outfile.mp3','wb') as output:
> output.write(mp3file.read())
>

Why not just use urlretrieve?

iMath 01-10-2013 02:08 AM

Re: how to download internet files by python ?
 
在 2013年1月8日星期二UTC+8下午1时04分54秒 Roy Smith写道:
> In article <mailman.259.1357620254.2939.python-list@python.org>,
>
> Cameron Simpson <cs@zip.com.au> wrote:
>
>
>
> > On 07Jan2013 20:19, iMath <redstone-cold@163.com> wrote:

>
> > | for example ,if I want to download this file ,how to implement the download

>
> > | functionality by python ?

>
> > |

>
> > | http://down.51voa.com/201208/se-ed-f...ds-16aug12.mp3

>
> > |

>
> > | as for download speed ,of course ,the fast ,the better ,so how to

>
> > | implement it ?

>
> > | It would be better to show me an example :) thanks !!!

>
> >

>
> > Look at urllib2.

>
>
>
> Even better, look at requests
>
> (http://docs.python-requests.org/en/latest/). There's nothing you can
>
> do with requests that you can't do with urllib2, but the interface is a
>
> whole lot easier to work with.


There is also a httplib2 module
https://code.google.com/p/httplib2/

which one is more pythonic and powerful ?


All times are GMT. The time now is 06:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.