我在这里找到了这个代码:Is there a way to get Bing's photo of the day?
很抱歉,我不能在这里发表评论,所以我在这里询问。但是我有一些问题。 当我在Debian中运行它时,它说“列表索引超出范围”,我不知道如何解决这个问题。我很抱歉,如果这听起来很愚蠢的话
#!/usr/bin/python3
from bs4 import BeautifulSoup
import os
import urllib
from urllib.request import urlopen
BingXML_URL ="http://www.bing.com/HPImageArchive.aspx?"
page= urlopen(BingXML_URL).read()
BingXml =BeautifulSoup(page, "lxml")
Images = BingXml.find_all('image')
ImageURL ="https://www.bing.com" + Images[0].url.text
ImageName = Images[0].startdate + ".jpg"
urllib.urlretrieve(ImageURL, ImageName)
您使用的链接与文章中所述的链接不同。文章说链接是
https://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US
,但您使用了
http://www.bing.com/HPImageArchive.aspx?
Bing对此没有回应。试试这个新链接,看看它是否有效
此外,还有一些小错误:
urlretrieve
在{Images[0].startdate
是Tag
对象,无法将其添加到str
{Images[0].startdate.get_text()
获取字符串并使用str
进行添加李>因此,完成的代码应该是:
相关问题 更多 >
编程相关推荐