python新人绘图_【python 【分享】 爬取一些二刺螈图片 (新手作图)
import requests
import bs4
import re
import os
url
↑網(wǎng)頁(yè)的頁(yè)數(shù) 第一頁(yè)與其他頁(yè)不同 所以暫無(wú)法爬取
header={"user-agent":"Mozilla/5.0(Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/57.0.2987.98 Safari/537.36"}
↓獲取網(wǎng)頁(yè)基本信息
def res_html():
url=url_f+str(number)+url_l
res=requests.get(url=url,headers=header)
res.encoding="utf-8"
return res
↓將信息初始處理
def bs4_html(res):
bs4_hou=bs4.BeautifulSoup(res.text,"html.parser")
return bs4_hou
將圖片的地址存貯到url_list中
def url_list(bs4_hou):
text_list=[]
url=[]
text=""
url_text=bs4hou.select("ul",class="clearfix")
for temp in url_text:
text_list.append(temp)
for temps in text_list:
text +=str(temps)
url=re.findall("/uploads/allimg/\d{6}/\d{6}-\w{14}.jpg",text)
return url
下載圖片
def download(url):
num=1
filefname="第 "
filelname=" 張圖片.jpg"
for temp in url:
filename="img\"+filefname+str(num)+filelname
a=open(filename,"wb")
durl="http://pic.netbian.com"+str(temp)
res=requests.get(url=durl)
a.write(res.content)
num+=1
print("已下載 "+str(num) +" 張圖片!")
download(url_list(bs4_html(res_html())))
總結(jié)
以上是生活随笔為你收集整理的python新人绘图_【python 【分享】 爬取一些二刺螈图片 (新手作图)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql 查询每天 如果没有显示为0_
- 下一篇: serverless 框架_Server