【发布时间】:2011-08-18 22:32:49
【问题描述】:
可能重复:
Beautiful Soup cannot find a CSS class if the object has other classes, too
我正在使用 BeautifulSoup 在 HTML 中查找 tables。我目前遇到的问题是在 class 属性中使用空格。如果我的 HTML 显示为 <html><table class="wikitable sortable">blah</table></html>,我似乎无法使用以下内容提取它(我可以在 wikipedia 和 wikipedia sortable 中找到 tables class):
BeautifulSoup(html).findAll(attrs={'class':re.compile("wikitable( sortable)?")})
如果我的 HTML 只是 <html><table class="wikitable">blah</table></html>,这将找到表格。同样,我尝试在我的正则表达式中使用"wikitable sortable",但这也不匹配。有什么想法吗?
【问题讨论】:
标签: python beautifulsoup