Python 2.7 使用Beautiful Soup4可以获得<;a>;嵌入文本?

Python 2.7 使用Beautiful Soup4可以获得<;a>;嵌入文本?,python-2.7,beautifulsoup,Python 2.7,Beautifulsoup,我正在将漂亮的Soup4与Python结合使用,现在,不管怎样,我都已经达到了下面的目的。那么现在我用什么方法可以得到狗、猫、马和ID的值呢。请帮忙 from bs4 import BeautifulSoup soup = BeautifulSoup(html_doc) soup.find_all('a') # [<a class="Animal" href="http://example.com/elsie" id="link1">Dog</a>, # <a

我正在将漂亮的Soup4与Python结合使用,现在,不管怎样,我都已经达到了下面的目的。那么现在我用什么方法可以得到狗、猫、马和ID的值呢。请帮忙

from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc)
soup.find_all('a')

# [<a class="Animal" href="http://example.com/elsie" id="link1">Dog</a>,
#  <a class="Animal" href="http://example.com/lacie" id="link2">Cat</a>,
#  <a class="Animal" href="http://example.com/tillie" id="link3">Horse</a>]
从bs4导入美化组
汤=美汤(html\U文档)
汤。找到所有的('a')
# [,
#  ,
#  ]


为什么使用unicode(值)?如果您不知道,
值将进入它!只是为了澄清我的理解!请帮忙!老实说,我这样做是因为文档中也提到了它:)“Navigablesting与Python Unicode字符串类似,只是它还支持导航树和搜索树中描述的一些功能。您可以使用Unicode()将Navigablesting转换为Unicode字符串。”
for a in soup.find_all('a'):
    id = a.get('id')
    value = a.string # This is a NavigableString
    unicode_value = unicode(value)