Python笔记:APP根据用户手机壳颜色来改变主题颜色?
写在前面
最近互联网出现了一个爆炸性的新闻:某互联网公司产品经理提出了一个需求,要求APP开发人员可以做到软件根据用户的手机壳来改变软件主题颜色!!!于是开发人员和产品经理打起来了!!!于是产品经理和开发人员都被辞退了!!!讲道理这个需求真的好难!臣妾真的是做不到啊!
博主忽然意识到一个事情,早在2016年互联网就出现了一个高科技有关的新闻:
中关村在线消息:谷歌再近些天发布了两款采用“动态”效果的手机壳,他们这些手机壳可以看出是非常漂亮的,同时这款手机壳背后还“暗藏”玄机:每天自动变更手机壁纸。这是通过背后的NFC触点实现的。这款手机采用了Google Earth的主题,可以每天从谷歌地球抓取新的地貌场景当做手机壁纸,同时还可以点击快捷键获取有关于这个地点的更多信息。
同时,锤子手机旗下的坚果手机,也可以根据后壳变换壁纸,只不过是通过触点实现的,没想到谷歌这款手机壳和锤子思路差不多。
高科技,实在是妙哉!妙哉!不得不叹服。
Python可以实现APP根据用户手机壳颜色来改变主题颜色?
正所谓,人生苦短,我用Python,产品经理提出的这个“APP根据用户的手机壳颜色来改变主题颜色?”能否用Python来实现呢?不如换一种实现方法吧,手机壳不能变色,我们让手机壁纸能够随心所欲的变换可以吗?产品经理您看这个需求就将就一下这样实现行吗?接下来我们就用Python写个爬虫实现自动抓取知乎上高大上的手机壁纸吧。执行代码之前需要安装好bs4这个包。如下图所示,在CMD命令里面执行:
pip install bs4
如果执行
pip install bs4
时出现以下错误提示:
需要先执行
python -m pip install --upgrade pip
升级PIP版本,升级完版本以后最好重新启动一下CMD控制台。完成以上bs4库的安装,接下来开始敲代码吧:
from bs4 import BeautifulSoup #从BeautifulSoup4(bs4)库里导入BeautifulSoup模块 from urllib import request #从urllib库里导入request模块 import re #导入正则表达式模块re模块 import time #导入time模块 url = "https://www.zhihu.com/question/64252714" html = request.urlopen(url).read().decode('utf-8') soup = BeautifulSoup(html, 'html.parser') links = soup.find_all('img', 'origin_image zh-lightbox-thumb', src = re.compile(r'jpg$')) print(links) path = r'E:\\Pictures\\bingImg' #保存到某个文件夹下 for link in links: print(link.attrs['src']) request.urlretrieve(link.attrs['src'], path + '\%s.jpg' % time.time())
敲好以上代码,在IDE工具里运行。接下来就是见证奇迹的时刻啦:
爬取的图片保存到本地文件夹:
产品经理,您看这样可以吗?这么多漂亮的手机壁纸,您可以随便更换,想要什么颜色您就换什么颜色!!!
作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可
文章评论(3)
It is appropriate time to make some plans for the future and it is
time to be happy. I have read this post and if I could I desire to suggest you few interesting things or advice.
Maybe you can write next articles referring to this article.
I desire to read even more things about it! It is the best time to
make some plans for the future and it is time to be happy.
I have read this post and if I could I wish to suggest you few interesting things or suggestions.
Perhaps you can write next articles referring to this
article. I desire to read more things about it! I am really inspired together with
your writing skills as well as with the layout
in your blog. Is that this a paid subject matter or did you modify it your self?
Either way keep up the excellent quality writing, it’s
rare to look a nice blog like this one these days..
产品经理和开发干起来了,哈哈
好强大!