##################################################
# 1. 请求页
import time
import requests
import re
headers = {
'user-agent': 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36'
}
# response = requests.get('https://www.vmgirls.com/13591.html', headers=headers)
response = requests.get('http://www.mculover666.cn/posts/1606619423/', headers=headers)
html = response.text
# print(response.request.headers)
# print(response.text)
# 2. 解析网页
# urls = re.findall('<a href="(.*?)" alt=".*?" title=".*?">', html)
# urls = re.findall('<img src=".*?" alt="mark">', html)
urls = re.findall('<img src=".*?" alt="mark">', html)
# <img src="http://mculover666.cn/image/20190806/9uiPTi5odYSj.png?imageslim" alt="mark">
print(urls)
# for url in urls:
# print(url.split('"')[1])
# 3. 保存图片
for url in urls:
# 延时
# time.sleep(1)
url = url.split('"')[1]
# print(url)
# 图片的名字
file_name = url.split('/')[-1].split('?')[0]
print(file_name)
response = requests.get(url, headers=headers)
# with open(file_name, "wb") as f:
# f.write(response.content)
【爬虫学习】一个简单的爬虫demo
猜你喜欢
转载自blog.csdn.net/ReCclay/article/details/104507271
今日推荐
周排行