点评赞转换
import re
def comments(comments_data):
comments_data = ''.join(comments_data)
if comments_data == '':
ir_nresrved2 = 0
ir_nresrved3 = 0
else:
comments_data = comments_data.replace('回應', '评论').replace('個', '条').replace('轉發', '分享').replace('萬', '万')
ir_nresrved2 = ''.join(re.findall('(.*?)条评论', comments_data))
if ir_nresrved2 == '':
ir_nresrved2 = '0'
ir_nresrved3 = ''.join(re.findall('条评论(.*?)次分享', comments_data))
if ir_nresrved3 == '':
ir_nresrved3 = ''.join(re.findall('(.*?)次分享', comments_data))
if ir_nresrved3 == '':
ir_nresrved3 = '0'
if '万' in ir_nresrved2:
ir_nresrved2 = ir_nresrved2.replace('万', '')
ir_nresrved2 = int(float(ir_nresrved2) * 10000)
if '万' in ir_nresrved3:
ir_nresrved3 = ir_nresrved3.replace('万', '')
ir_nresrved3 = int(float(ir_nresrved3) * 10000)
return ir_nresrved2, ir_nresrved3
# print(f'评论:{ir_nresrved2}, 转发:{ir_nresrved3}')
comments_data = ['6次分享']
# comments_data = ['12条评论6次分享']
# comments_data = ['12条评论', '6次分享']
# comments_data = ['12条评论', '6次分享','12条评论', '6次分享']
# comments_data = ['12条评论','12条评论', '6次分享']
# comments_data = ['12条评论']
# comments_data = []
print(len(comments_data), comments_data)
if len(comments_data) == 0:
ir_nresrved2 = 0
ir_nresrved3 = 0
comments(comments_data)
elif len(comments_data) == 1:
comments(comments_data)
elif comments_data[1][-3:] == comments_data[0][-3:]:
comments_data = comments_data[0]
comments(comments_data)
else:
comments_data = ''.join(comments_data[0] + comments_data[1])
comments(comments_data)
ir_nresrved2 = comments(comments_data)[0]
ir_nresrved3 = comments(comments_data)[1]
ir_nresrved1 = ['1.3xa0万']
if ir_nresrved1 == []:
ir_nresrved1 = 0
else:
ir_nresrved1 = (''.join(ir_nresrved1)).replace('xa0', '')
if '万' in ir_nresrved1:
ir_nresrved1 = ir_nresrved1.replace('万', '')
ir_nresrved1 = int(float(ir_nresrved1) * 10000)
print(ir_nresrved1, ir_nresrved2, ir_nresrved3)
本文作者:布都御魂
本文链接:https://www.cnblogs.com/wolvies/p/15424158.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步