import re
import time
import requests
#上面是导包啊
#防止反爬,加个这个
header = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}
#获取页面内容昂
response = requests.get('https://www.vmgirls.com/19512.html',headers = header)
#保存为文本昂
html = response.text
#得到要爬的照片的格式昂,得到一个数组,这个网址的图片标签是a标签样式的,具体网站具体分析昂,用到了正则表达式
urls = re.findall('<a rel=".*?" href="(.*?)" alt=".*?" title=".*?">',html)
#print(urls)
#for循环
for url in urls:
#减减速度,心机爬不了热图片
time.sleep(1)
#得到图片名
file_name = url.split('/')[-1]
#得到图片链接
response = requests.get(url,headers = header)
#用文件形式保存下来
with open(file_name,'wb') as f:
f.write(response.content)
#这个是要爬取的图片的标签格式
##<a rel="nofollow" href="https://img.vm.laomishuo.com/image/2022/05/2022053113081017.jpg" alt="我的春日游记" title="我的春日游记">
Python爬取图片------easy版
最新推荐文章于 2024-07-27 17:39:19 发布