use*_*925 6 python tags parsing beautifulsoup
有人可以指导我如何使用BeautifulSoup来提取标签的价值吗?我阅读了文档,但很难浏览它.例如,如果我有:
<span title="Funstuff" class="thisClass">Fun Text</span>
Run Code Online (Sandbox Code Playgroud)
我怎样才能将"Funstuff"拉到BeautifulSoup/Python?
编辑:我使用的是版本3.2.1
你需要有一些东西来识别你正在寻找的元素,而且很难说出这个问题是什么.
例如,这两个都将打印出BeautifulSoup 3中的"Funstuff".一个查找span元素并获取标题,另一个查找具有给定类的跨度.许多其他有效的方法可以达到这一点.
import BeautifulSoup
soup = BeautifulSoup.BeautifulSoup('<html><body><span title="Funstuff" class="thisClass">Fun Text</span></body></html>')
print soup.html.body.span['title']
print soup.find('span', {"class": "thisClass"})['title']
Run Code Online (Sandbox Code Playgroud)