先来看一下效果吧,只要有足够的照片素材,捕获女神的心就指日可待
怎么样,看起来还可以吧
下面就一起来完成吧
数据准备
首先是测试图片的获取,毕竟萝卜哥当前还没有那么多女神的照片
这里我使用如下网站的高清图片,嗯,各个都是大美女
http://lab.mkblog.cn/wallpaper/
抓取的代码比较简单
import requests
import json
def get_pic():
headers = {"Accept": "application/json, text/javascript, */*; q=0.01",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
"Cookie": "Hm_lvt_6e8dac14399b608f633394093523542e=1607173561; Hm_lvt_ea4269d8a00e95fdb9ee61e3041a8f98=1621344383; Hm_lpvt_ea4269d8a00e95fdb9ee61e3041a8f98=1621344423",
"Referer": "http://lab.mkblog.cn/wallpaper/"}
pic_url = "http://lab.mkblog.cn/wallpaper/api.php?cid=6&start=0&count=100"
pic_res = requests.get(pic_url, headers=headers)
pic_res_json = pic_res.json()
pic_info = pic_res_json.get("data")
pic_url = []
num = 0
try:
for i in pic_info:
if num % 5 == 0:
pic_url.append(i["url"])
if num % 5 == 1:
pic_url.append(i["img_1600_900"])
if num % 5 == 2:
pic_url.append(i["img_1366_768"])
if num % 5 == 3:
pic_url.append(i["img_1280_800"])
if num % 5 == 4:
pic_url.append(i["img_1024_768"])
num += 1
except:
pass
return pic_url
def save_pic_url(data):
json.dump(data, open("pic_url.json", 'w'))
if __name__ == '__main__':
pic_url = get_pic()
save_pic_url(pic_url)
因