请问大家Python怎样下载一个url请求的文件,可能我描述的不是很清楚,直接贴代码。
比如是这样的url:http://www.aaa.com/download.php?aid=123
在浏览器中打开这个url,就会直接下载一个文档,请问如何用Python下载这个url指向的文档?
PHPz2017-04-17 17:32:50
Just write to the file
f=urllib2.urlopen(url)
data=f.read()
f=open(path,'wb')
f.write(data)
f.close()
ringa_lee2017-04-17 17:32:50
There is a problem with the above answer. There is no urlretrieve function in urllib2. This function is in urllib.
伊谢尔伦2017-04-17 17:32:50
The simplest implementation is to use wget
Installation
pip install wget
Use
import wget
wget.download("http://xxx.xxx.com/xx.mp4")
ringa_lee2017-04-17 17:32:50
Directly use the requests library to download. There are many examples on the Internet. There are also corresponding download methods for large files.