美文网首页
python必应首页背景图片获取

python必应首页背景图片获取

作者: 青鸟_cyan | 来源:发表于2017-05-25 21:49 被阅读0次

在美工的期盼下搞出来的小玩意,运用requests库进行的图片爬取。运用的是图片网址一贯的规律,所以过一段时间也是有可能失灵的,大家有需要可以参考一下。

import requests

import re

from bs4 import BeautifulSoup

URL = requests.get('https://cn.bing.com')

soup = BeautifulSoup(URL.text,'lxml')

html = soup.find_all('script')

html =str(html)

reg = re.compile('az.*?jpg+', re.M | re.S)

out = reg.search(html).group()

iurl ='https://cn.bing.com/'+out

im = requests.get(iurl).content

with open('你的路径,最后一个写希望保存的图片名.jpg','wb')as imf:

imf.write(im)

相关文章

网友评论

      本文标题:python必应首页背景图片获取

      本文链接:https://www.haomeiwen.com/subject/jpozxxtx.html