2016-09-28 82 views
1

我以前使用的Linux终端上使用wget -r下载带有特定扩展名的文件:下载特定文件

wget -r -A Ext URL 

但现在我在这里的讲师分配用来做同样的事情PHP或Python。谁可以帮忙?

回答

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

对于Python,使用web爬虫库如scrapy。

它有classes当传递类似于你放在wget命令行上的参数时,它会完成所有的工作。

您可以使用scrapy pipelines来过滤不需要的下载,并增值下载,例如添加缩略图。