相关疑难解决方法(0)

BeautifulSoup和按类搜索

可能重复:
如果对象也有其他类,Beautiful Soup也找不到CSS类

我正在使用BeautifulSoup tables在HTML中查找.我目前遇到的问题是在class属性中使用空格.如果我的HTML读取<html><table class="wikitable sortable">blah</table></html>,我似乎无法使用以下内容提取它(我可以在tables两者中找到它wikipedia并且wikipedia sortable用于class):

BeautifulSoup(html).findAll(attrs={'class':re.compile("wikitable( sortable)?")})
Run Code Online (Sandbox Code Playgroud)

如果我的HTML就是这样,我们会找到该表<html><table class="wikitable">blah</table></html>.同样,我尝试"wikitable sortable"在我的正则表达式中使用,但也不匹配.有任何想法吗?

python beautifulsoup

13
推荐指数
2
解决办法
3万
查看次数

标签 统计

beautifulsoup ×1

python ×1