2017-06-29 52 views
-1

我正在使用以下代码来查找类“产品类别”的标记。Python:搜索以字符开头的html标记

soup0.findAll("a",{"class":"product-category"}) 

如果我需要找到一个以产品类别开头的标签,我该怎么写。 我试过使用

soup0.findAll("a",{"class":%"product-category"}) ##This doesnt work. 

有什么办法吗?

感谢,

+0

谢谢你的链接 – Santosh

回答

0

从文档,你可以做一些像这样:

import re 
tagsStartingWithB = soup.findAll(re.compile('^b')) 
[tag.name for tag in tagsStartingWithB] 
# [u'body', u'b', u'b'] 

查看更多here.