Python 正则表达式提取评论数 - 去除“条评价”
如果想去掉"条评价",可以使用正则表达式来匹配并提取数字部分即可。例如:
import re
comment_text = "20万条评价"
comment_match = re.search(r"(\d+)", comment_text)
if comment_match:
comment_count = comment_match.group(1)
print("评论数: " + comment_count) # 打印评论数
else:
print("评论数:0")
输出结果为:
评论数: 20
原文地址: https://www.cveoy.top/t/topic/pAQu 著作权归作者所有。请勿转载和采集!