本次爬取运用到了requests,bs4的beautifulsoup好,re以及time模块,用了常用的方法提取到源代码的关键信息,最后获取每个信息的请求链接,从而获得我们的图片。
import requests
from bs4 import BeautifulSoup
import re
import time
url='https://www.''此处为需要获取的网站.cc/bizhitupian/'
res=requests.get(url)
obj=re.compile(r'
.*?)"> res.encoding='uft-8'
res.close()
res=res.text
res=BeautifulSoup(res,'html.parser')
res=res.find_all('div',class_="pic-box")
res=str(res).strip('[]')
result=obj.finditer(res)
for it in result:
url1='https://www.umei.cc'+it.group('http')
response = requests.get(url1)
response.encoding='utf-8'
response=response.text
response=BeautifulSoup(response,'html.parser')
name=response.find('title')
name=str(name)
name=name.strip('')
img=response.find('img')
img = img.get('src')
rs=requests.get(img).content
with open('img/'+name+'.jpg','wb')as f:
f.write(rs)
print('完成了',name)
time.sleep(2)#怕请求太过频繁造成不必要的影响,所以设置了一定的延迟
print("全部完成拉!")
今天分享的内容就这些啦,希望大家有不好的地方可以提出来,帮我指正指正!
(效果图片)



