Python BeautifulSoup4 get_text()或正则表达式

Python BeautifulSoup4 get_text()或正则表达式,python,regex,beautifulsoup,Python,Regex,Beautifulsoup,我正在使用Python2.7.5和BeautifulSoup4。 我需要从html标签中剪切文本。 我在命令后输出了: print post_owner[0] 我只需要昵称:鸣人 并且不想使用get\u text() 我的代码: post_owner = soup.findAll(attrs={'class':'username offline popupctrl'}) for row1 in post_owner: text = ''.join(row1.findAll(text

我正在使用Python2.7.5和BeautifulSoup4。 我需要从html标签中剪切文本。 我在命令后输出了

  print post_owner[0]
我只需要昵称:
鸣人
并且不想使用
get\u text()

我的代码:

post_owner = soup.findAll(attrs={'class':'username offline popupctrl'})
for row1 in post_owner:
    text = ''.join(row1.findAll(text=True))
    data1 = text.strip()
    text_file.write("USER NAME\n")
    member_count = member_count + 1
    data1 = data1.encode('utf-8')
    text_file.write(str(data1) + '\n')
我在其他帖子中使用了一些解决方案。如果我理解正确,
findAll
会给我一个所有匹配项的列表。我的代码将打印一行中的所有匹配项。我只需要访问
post_owner
列表中的元素,并在没有html标记的情况下使用它们。例如:

  print post_owner[0]
  print post_owner[4]
  print post_owner[2]
  .
  .
  .

抱歉解释得不好,我真的很累:o

使用
汤。选择
get()


[i.get('title')代表汤中的i。选择('.username')]

当它显然是最好的选择时,为什么不使用
get_text
?因为当我将get_text与findAll一起使用时,它会返回错误代码。具体的错误消息是什么?AttributeError:'ResultSet'对象没有属性'find'