Q
下载特定文件
1
A
回答
1
您可以使用PHP函数file_get_contents()
检索文件的内容。该函数的第一个参数是filename,它可以是文件的本地路径或URL。
见例如从PHP docs
<?php
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
?>
2
我猜的urllib相当不错,你
import urllib
urllib.urlretrieve (URL, file)
0
或者,你可以使用Requests:请求是唯一的非转基因HTTP的Python库,可安全食用。
(从DOC)实施例:
>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
>>> r.status_code
200
>>> r.headers['content-type']
'application/json; charset=utf8'
>>> r.encoding
'utf-8'
>>> r.text
u'{"type":"User"...'
>>> r.json()
{u'private_gists': 419, u'total_private_repos': 77, ...}
0