使用类名bs4和Python 2.7查找值“age”

时间:2017-11-21 00:43:32

标签: python-2.7 beautifulsoup

HTML:

<div class="person" age="52"</div>

我想用bs4

获得年龄值

我试过了:

soup = BeautifulSoup(source, "lxml") #source is the page.text
age = soup.find("div", { "class": "person" })["age"]

但是每次运行时,我都会得到一个None值,好像该元素不存在一样。

0 个答案:

没有答案