Python爬虫-小爱同学感恩节活动-感恩信
2019-12-05 本文已影响0人
PLUSLEE
2019年11月28日,把玩了好几个月的小米9SE,推送了一条消息“小爱 『同学们』的感恩信”,顺手点开开启感恩信,第一篇就是Are U OK的雷军。
![](https://img.haomeiwen.com/i173881/adb7a1be9b0d4254.jpg)
嘿,闲来无事,顺手点点,发现小爱同学里应该都是优秀的人才啊。
出于对小米系统的喜爱,处于对小爱同学语音助手的喜爱,决定将所有的感恩信全部下载下来,留存备份。项目代号“爱了爱了”。
挑选一些自己认为比较有意思的明信片。
![](https://img.haomeiwen.com/i173881/8ea7b85f280899cc.jpg)
![](https://img.haomeiwen.com/i173881/3bc6e21ec4476ba8.jpg)
![](https://img.haomeiwen.com/i173881/4dbf805033fd84b3.jpg)
![](https://img.haomeiwen.com/i173881/117afd7d62e77ce6.jpg)
![](https://img.haomeiwen.com/i173881/9289739f64d1a549.jpg)
![](https://img.haomeiwen.com/i173881/a0b3c52a013eee69.jpg)
![](https://img.haomeiwen.com/i173881/5537e6e7eb67d69d.jpg)
![](https://img.haomeiwen.com/i173881/3b30b8b6297395bc.jpg)
![](https://img.haomeiwen.com/i173881/b330e2f40fe20ede.jpg)
![](https://img.haomeiwen.com/i173881/7c54c62f882cca0a.jpg)
# -*- coding: utf-8 -*-
'''
获取小米感恩节中小爱同学的所有祝福卡片
'''
from selenium import webdriver
from grab import Grab
import os
import requests
import time
def getSources(i=None):
level = driver.find_element_by_class_name('index_title__2AG9z').get_attribute('textContent')
# print(level)
pic_url = driver.find_element_by_class_name('index_letterImg__3DlbL').get_attribute('src')
# print(pic_url)
# 获取图片
img = requests.get(pic_url)
# 保存图片到指定文件夹下
path = 'D:\Sources\XiaoMiThanksgivingDay\pic'
# 如果没有对应文件夹,自动创建文件夹
if not os.path.isdir(path):
os.mkdir(path)
paths = path + '\\'
# 按照level和读取顺序保存图片
file = open(paths + level + str(i) + '.jpg', 'ab')
file.write(img.content)
print(level + str(i), '文件保存成功!')
file.close()
return pic_url
if __name__ == '__main__':
driver = webdriver.Chrome()
driver.get('https://i.ai.mi.com/h5/ai-thanksgiving-letter-fe/#/letter')
for i in range(1, 300):
old_url=getSources(i)
# 点击进入下一张图片
driver.find_element_by_class_name('index_nextButton__2CRzD').click()
time.sleep(5)
在这些代码基础上,开始下载保存图片。因为一开始没有确认一共有多少感谢信,只设置下载到299张。后来仔细阅读发现,一共其实是608人。
所以现在这299张图片的基础上进行一个分析。图片中有部分重复,但不影响产品经理、工程师、设计师之间的比例。至于为什么会重复,答案未知。(也许代码可以修改为判断是否是同一张图片,如果是就不去下载了。然后for循环他个1000次)
以下是图片截图:
设计师篇:不愧是设计师,过大半比例都是涂涂画画,还挺好看。
![](https://img.haomeiwen.com/i173881/cc2a9090faf1c671.png)
工程师篇:符合大家对工程师的认知,文字为主,图片为辅,不乏特色。
![](https://img.haomeiwen.com/i173881/7366d269569a675c.png)
![](https://img.haomeiwen.com/i173881/f25d4e1843b67338.png)
![](https://img.haomeiwen.com/i173881/95c70a5af369265b.png)
![](https://img.haomeiwen.com/i173881/821f27045436fbbd.png)
![](https://img.haomeiwen.com/i173881/7c9169fb40f08ceb.png)
产品经理篇:恩,产品经理的感谢信介于工程师与设计师之间吧,风格各异,有个性的极具个性。
![](https://img.haomeiwen.com/i173881/8d592f6ae6915e75.png)
![](https://img.haomeiwen.com/i173881/571607359008908e.png)
![](https://img.haomeiwen.com/i173881/6c63389759325581.png)
产品经理89张,工程师179张,设计师37张。
PM:RD:Designer=89:179:37≈3:6:1,从这个关系中可以看出小爱同学的整个项目中,开发工程师占据的大半,产品经理占据三成,设计师比例一成。
项目源码与收集到的资源在Github上,地址: