我想我知道了:
>>> [div['class'] for div in soup.find_all('div')][['comment', 'form', 'new'], ['comment', 'comment-xxxx...']]请注意,与BS3中的等效项不同,它不是这样的:
['comment form new', 'comment comment-xxxx...']
这就是为什么您的正则表达式不匹配的原因。
但是您可以匹配,例如:
>>> soup.find_all('div', class_=re.compile('comment-'))[<div ></div>]请注意,BS等效于BS
re.search,而不是
re.match,所以您不需要
'comment-.*'。当然,如果您想匹配
'comment-12345'但不
'comment-of-another-kind想要,例如
'comment-d+'。



