下載指定網站上的妹子圖片,這裏只抓了前100頁的圖片,可根據須要本身設置頁數
cat值爲圖片類型,你們能夠自行更改cat值體驗一下,有問題留言給我,看到就會解答
2 = 大胸妹
3 = 美腿控
4 = 有顏值
5 = 大雜燴
6 = 小翹臀html
import requests import re import time from bs4 import BeautifulSoup cat ='2' img = 'http://www.dbmeinv.com/dbgroup/show.htm?cid='+ cat end = '/dbgroup/show.htm?cid='+ cat + '&pager_offset=100' urls = [ ] def getURLs(mainURL): time.sleep(1) headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36'} html = requests.get(mainURL).text soup = BeautifulSoup(html, 'html.parser') picURL = re.findall('<img class.*?src="(.+?\.jpg)"', html, re.S) for url in picURL: urls.append(url) print(url) asoup = soup.select('.next a')[0]['href'] Next_page = 'http://www.dbmeinv.com' + asoup if asoup != end: getURLs(Next_page) else: print('連接已處理完畢!') return urls url = getURLs(img) i = 0 for each in url: pic = requests.get(each, timeout = 10) picName = 'pictures/' + str(i) + '.jpg' fp = open(picName, 'wb') fp.write(pic.content) fp.close() i += 1 print('圖片下載完成')