如何使用python获取特定图像?

时间:2018-06-15 15:59:40

标签: python beautifulsoup

我想从wwww.wikiart.org获取当天图片的艺术作品 我试过这段代码:

from urllib import request
from bs4 import BeautifulSoup
from datetime import datetime as dt
import requests,os


def get_image():
    res=requests.get('https://www.wikiart.org/')
    soup=BeautifulSoup(res.text,"lxml")
    image=soup.find('a',{'class':'cursor_zoom'}).find('img')
    link=image.get('src')
    return link

def download():
    link=get_image()
    file_name = dt.now().strftime("%Y-%m-%d")
    user = os.getenv('USER')
    path='/home/'+user+'/Pictures/ArtWallpapers'
    full_path=os.path.join(path,file_name)

    if not os.path.exists(path):
        os.mkdir(path)

    with open(full_path, 'wb') as f:
        f.write(request.urlopen(link).read())
    return full_path

def change_wall():
    full_path=download()
    os.system("/usr/bin/gsettings set org.gnome.desktop.background picture-uri file:///"+full_path)


change_wall()

然后我失败了,它说“AttributeError:'NoneType'对象没有属性'find'”我该怎么办才能解决它?

0 个答案:

没有答案