美丽的Soup提取标题内容

2024-04-29 11:11:57 发布

您现在位置:Python中文网/ 问答频道 /正文

使用BeautifulSoup如何获得标题的内容。 假设我想得到下面的“我是一个头衔”:

h4 class="title" title="I am a title"

我看不出哪里出了问题,我一直在犯这个错误:

AttributeError: 'NoneType' object has no attribute 'attrs'

运行时:

product_name = self.parent.select_one(locator).attrs['title']

Tags: no标题内容objecttitle错误amattrs