import requests
url = “https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1418911644,714422356&fm=11&gp=0.jpg”
headers = {“User-Agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36”}
response = requests.get(url,headers=headers)
# 使用content获取响应内容
data = response.content
with open(“刘亦菲.jpg”,“wb”) as f:
f.write(data)
“”"
1.找一个图片网站,使用正则提取网页中的图片链接
http://www.win4000.com/mt/liuyifei.html
“”"
import re
def tupian(url,i):
urls = url
response = requests.get(urls, headers=headers)
data = response.content
with open("1%d.jpg"%i, "wb") as f:
f.write(data)
name = input(“请输入要下载的明星:”)
urls = “http://www.win4000.com/mt/” + name + “.html”
print(urls)
headers = {“User-Agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36”}
response = requests.get(urls,headers=headers)
response.encoding = “utf-8”
html = response.text
f = re.findall(’
-
.
?<img src="(.?)"’,html,re.S)
f = re.findall(’<img.?src="(.?)"’,html,re.S)
print(len(f))
for i in range(len(f)):
tupian(f[i],i)