【发布时间】:2021-07-29 04:59:49
【问题描述】:
运行以下代码时
sneaker_info.find(lambda tag: tag.name == 'td' and re.compile('Size') in tag.text)
我收到此错误
TypeError: 'in <string>' requires string as left operand, not re.Pattern
我知道我可以使用
sneaker_info.find(lambda tag: tag.name == 'td' and 'Size' in tag.text)
但我想使用正则表达式模式来提取所需的信息。
有没有办法绕过这个错误?
P.S 我也不能在这段 HTML 上使用sneaker_info.find('td', string=re.compile(r'Size'))
【问题讨论】:
-
尝试使用 str(re.compile(r'Size'))
-
@Luiz 你认为那会怎样?
-
转成字符串,只是猜测,想帮忙
标签: python regex beautifulsoup