【发布时间】:2017-06-30 22:21:55
【问题描述】:
我正在尝试抓取 tumblr 存档,div 类标签看起来像图片中给出的
课程以“post post_micro”开头,我尝试使用正则表达式但失败了
soup.find_all(class_=re.compile('^post post_micro')
我尝试将 find_all 中的函数用于类
def func(x):
if str(x).startswith('post_tumblelog'):
return True
并将其用作:
soup.find_all(class_=func)
以上工作正常,我得到了我需要的东西。但我想知道如何使用正则表达式以及为什么在 func(x) 中,
str(x).startswith('post_tumblelog')
当类名以“post post_micro”开头时评估为 True。
【问题讨论】:
标签: python regex beautifulsoup