【发布时间】:2014-05-04 19:54:17
【问题描述】:
我正在尝试在 div 中提取前面带有哈希标记的名称。
<div class="h_names">#jason, #michael, #sam, etc...</div>
所以我的结果将是jason、michael、sam 等的列表。
我不确定如何使用 BeautifulSoup 做到这一点。
import bs4
soup = bs4.BeautifulSoup(html)
div = soup.find('div', {'class' : 'h_names'})
这会找到 div,但我需要一个正则表达式来提取名称
【问题讨论】:
-
查看网站上的文档,如果您将来使用 bs4,绝对值得一读,而且不难掌握crummy.com/software/BeautifulSoup
标签: python regex beautifulsoup