2024-04-29 11:11:57 发布
网友
使用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']
下面是一个工作示例:
>>> from bs4 import BeautifulSoup >>> soup = BeautifulSoup('<html><h4 class="title" title="I am a title">test</h4></html>') >>> soup.find(attrs={'class': 'title'})['title'] 'I am a title'
下面是一个工作示例:
相关问题 更多 >
编程相关推荐