初学者通过网络抓取错误
TypeError:“ NoneType”对象不可下标
res=requests.get("https://www.brainyquote.com/quote_of_the_day")
soup=BeautifulSoup(res.text,'lxml')
image_quote=soup.find('img', {'class':'p-qotd bqPhotoDefault bqPhotoDefaultFw img-responsive'})
print(image_quote['alt'])
我希望将输出作为当天的报价。而是收到此错误。
答案 0 :(得分:0)
尝试以下代码:-
import requests
from bs4 import BeautifulSoup
# getting HTML from the Google Play web page
res=requests.get("https://www.brainyquote.com/quote_of_the_day")
soup=BeautifulSoup(res.text,'lxml')
image_quote = soup.find('img', {'class':'p-qotd'})
print(image_quote['alt'])
# print(soup)
您的代码无效,因为您指定了所有类。只需指定唯一的类