我的python报废程序遇到了TypeError
这是我的密码:
from bs4 import BeautifulSoup
import requests, feedparser
cqrss = feedparser.parse('https://www.reddit.com/r/pics/new.rss')
for submission in cqrss.entries:
folder_name = submission.title #use for create folder
reddit_url = submission.link
source = requests.get(reddit_url)
plain_text = source.content
soup = BeautifulSoup(plain_text, 'lxml')
title = soup.find('a', 'title may-blank outbound', href=True)
if 'imgur.com' in title['href']:
imgur_link = title['href']
print(imgur_link)
错误:
if 'imgur.com' in title['href']:
TypeError: 'NoneType' object is not subscriptable
我做错了什么
find
对某些数据“失败”(即找不到任何内容),并返回None
应该有用
请注意,
print
在if
子句下移动,因为如果数据不在那里,调用它显然没有意义相关问题 更多 >
编程相关推荐