问题遇到的现象和发生背景
爬虫时出现的错误
问题相关代码,请勿粘贴截图
for comment in comments:
uersname=comment.find("a")["title"] and comment.find("a")["title"] or ""
rating=comment.find("span",{"class":"rating"})["title"] and comment.find("span",{"class":"rating"})["title"] or""
time=comment.find("span",{"class":"comment-time"}).text.split()[0]
content=comment.find("span",{"class":"short"}).text and comment.find("span",{"class":"short"}).text or ""
vote=comment.find("span",{"class":"vote-count"}).text and comment.find("span",{"class":"vote-count"}).text or ""
data=uersname+";"+time+";"+content+";"+vote+"\n"
print(rating)
运行结果及报错内容
我的解答思路和尝试过的方法
去掉["title"]不会报错,但不是我想要的结果
我想要达到的结果
消除报错,并能运行此代码。