爬取斗图网图片
因為初學python,就寫了簡單爬蟲,爬取了一些表情包,后期還會利用scrapy框架爬取小說等其他東西
廢話不多說,直接上代碼
#導入模塊 import requests from bs4 import BeautifulSoup #定義路徑 path=r'D:\斗圖2' #給圖片取名字,從1開始 count=1 #爬取10頁表情包 for i in range(1,11):response=requests.get(r'http://www.bbsnet.com/page/'+str(i))response.encoding='utf-8' soup=BeautifulSoup(response.text,'html.parser')# imgs=soup.find_all('img') # print(imgs) imgs=soup.select('div > div > ul > li > div > a > img')for img in imgs:if img['src'][-3:]=='gif':data=requests.get(img['src'])# print(data) #路徑拼接 file=open(path+'\\'+str(count)+img['src'][-4:],'wb')file.write(data.content)file.close()count+=1總結
- 上一篇: CountDownLatch:别浪,等人
- 下一篇: 最新android 8手机图片,手机QQ