Python学习笔记:爬虫下载图片

2019-04-15 16:53发布

import requests,urllib.request from bs4 import BeautifulSoup url='http://jandan.net/pic/page-547#comments' folder_path='/home/daya/Downloads/' download_links=[] wb_data=requests.get(url) soup=BeautifulSoup(wb_data.text,'lxml') pic_link=soup.select('a.view_img_link') for link in pic_link: pic_src=link.get('href').replace('//','http://') #构造完整链接 download_links.append(pic_src) for item in download_links: urllib.request.urlretrieve(item,folder_path+item[-10:]) #下载方法,文件全名截取后十位 print('Done')
速度太慢了