【发布时间】:2019-10-26 08:54:47
【问题描述】:
我正在使用 Python 3.7 和 BeautifulSoup 4。当我执行 findAll 时,如何找到匹配元素的数量?我有这个
# Verify that we didn't see a no results message
no_images_msg = "No very similar images were found on Reddit."
elts = soup.body.findAll(text=re.compile("^.*" + no_images_msg + ".*$"))
if elts.count != 0:
print("nothing found" + str(elts.count))
print(str(elts))
return json.dumps(results)
但 "elts.count != 0" 子句的计算结果始终为 true,即使通过 print 语句,我也可以看到没有元素。
【问题讨论】:
标签: python regex python-3.x beautifulsoup match