13行MATLAB代码实现网络爬虫 爬取NASA画廊星图
2021/04/18上传
2021/04/21更新:修改N
的输入方式,增加对png
格式图片的下载支持,增加了自动处理几种错误情况的代码,能够将下载过程与报错记录保存到日志中。
源代码
N = input('Input the number you want to download:');
URL = 'https://www.nasa.gov/api/2/ubernode/_search';
mainURL = 'https://www.nasa.gov/sites/default/files/';
opt = weboptions('Timeout',10);
for i=1:N
data = webread(URL,'size',num2str(N),'from','0','sort','promo-date-time:desc','q','((ubernode-type:image) AND (routes:1446))','_source_include','promo-date-time,master-image,nid,title,topics,missions,collections,other-tags,ubernode-type,primary-tag,secondary-tag,cardfeed-title,type,collection-asset-link,link-or-attachment,pr-leader-sentence,image-feature-capt