Python 3.x 在BeautifulSoup/Python中,如何从结果集中提取单个元素?

Python 3.x 在BeautifulSoup/Python中,如何从结果集中提取单个元素?,python-3.x,beautifulsoup,resultset,Python 3.x,Beautifulsoup,Resultset,我正在使用Python3.7和Beautifulsoup4。从元素获取文本时遇到问题。我在试这个 req = urllib2.Request(fullurl, headers=settings.HDR) html = urllib2.urlopen(req, timeout=settings.SOCKET_TIMEOUT_IN_SECONDS).read() bs = BeautifulSoup(html, features="lxml") ... author_elts = bs.find_a

我正在使用Python3.7和Beautifulsoup4。从元素获取文本时遇到问题。我在试这个

req = urllib2.Request(fullurl, headers=settings.HDR)
html = urllib2.urlopen(req, timeout=settings.SOCKET_TIMEOUT_IN_SECONDS).read()
bs = BeautifulSoup(html, features="lxml")
...
author_elts = bs.find_all("a", class_="author")
author_elt = author_elts.first
但是在author\u elt=author\u elts.first行,我得到了错误

AttributeError: ResultSet object has no attribute 'first'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()

从结果集中提取元素的正确方法是什么?

查找所有返回列表,为什么不使用author\u elts[0]获取第一个元素?

这是否回答了您的问题?