meizi

爬取妹子图片

谁说胖子不能爱 提交于 2021-02-15 11:08:24
废话不多说,直接上代码 非原创 原作者记不得了 import requests from bs4 import BeautifulSoup def imgurl(url): res = requests.get(url) soup = BeautifulSoup(res.text, 'html.parser') # 获取总页数 page = int(soup.select('.pagenavi span')[-2].text) # 获取图片链接 a = soup.select('.main-image a')[0] src = a.select('img')[0].get('src') meiziid = src[-9:-6] print('开始下载妹子:',format(meiziid)) for i in range(1, page+1): i = '%02d' % i img = src.replace('01.jpg', str(i)+'.jpg') headers = { 'User-Agent':'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)', 'Referer':'http://www.mzitu.com' } #此请求头破解防盗链 response = requests.get(img,headers