1 Star 0 Fork 1

decrement/web维修

forked from 风之羽/web维修 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bing.py 620 Bytes
一键复制 编辑 原始数据 按行查看 历史
风之羽 提交于 2020-10-12 17:54 . 6
#!~/m_statistics/env/bin python
# coding: utf-8
import requests
import re
import os
from bs4 import BeautifulSoup
base = os.path.dirname(os.path.abspath(__file__)) + '/static/slide/'
r=requests.get('https://cn.bing.com/?FORM=BEHPTB')
soup = BeautifulSoup(r.text, 'html.parser')
bg=soup.find(id="bgLink")
# 下载图
img=requests.get('https://cn.bing.com'+bg['href'])
if img.status_code== requests.codes.ok:
# 保存
pattern=re.compile(r'id=(.+\.jpg)?')
image_file_name = pattern.findall(bg['href'])[0]
with open(base + image_file_name,'wb') as f:
f.write(img.content)
else:
print('get bing image failed')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/decrement/m_statistics.git
git@gitee.com:decrement/m_statistics.git
decrement
m_statistics
web维修
master

搜索帮助