我尝试从类中检索图像标题但只得到以下错误:TypeError:' NoneType'对象不可调用
源代码如下:
> <span class="serien-heute-terminblock"><span class="img-wrap"><img
> title="ARD-alpha" alt="ARD-alpha"
> src="https://bilder.fernsehserien.de/logos/svg/10.svg"></span>heute</span>
我尝试过以下两种方法,但都不起作用:
for sender in doc.findALL("span", {"class":"serien-heute-terminblock"}):
sender_titel = sender.getText("img title")
print(sender_titel)
和
for sender in doc.findALL("span", {"class":"img-wrap"}):
sender_titel = sender.getText("img title")
print(sender_titel)
感谢您的帮助。
答案 0 :(得分:0)
find_all
或findAll
代替findALL
。
import requests
from bs4 import BeautifulSoup
example = """
<span class="serien-heute-terminblock"><span class="img-wrap">
<img title="ARD-alpha" alt="ARD-alpha
src="https://bilder.fernsehserien.de/logos/svg/10.svg"></span>heute</span>"""
soup = BeautifulSoup(example, "lxml")
for sender in soup.find_all("span", {"class":"serien-heute-terminblock"}):
sender_titel = sender.find("img")
if sender_titel is not None:
print (sender_titel["title"])
ARD-α