【发布时间】:2021-01-12 08:46:15
【问题描述】:
当我打印“金额”时,我得到了重复的值。这是否与我的前三行中的两个 for 循环有关?
缺失金额:
['102,131.49']
预期结果:
102,131.49
实际结果:
102,131.49
102,131.49
代码: 身体_l = [] 对于 url 中的链接: body = browser.find_element_by_xpath("//[contains(text(), 'Total:')]").text body_l.append(正文) icl_dollar_amount = re.findall('(?:[\£$\€]{1}[,\d]+.?\d)', body)[0].split('$', 1 )[1] icl_dollar_amount_l.append(icl_dollar_amount) 如果没有缺失金额: logging.info("列表为空") print("列表为空") 计数 = 0 对于missing_amount中的金额: 对于计数,枚举中的项目(icl_dollar_amount_l): 如果金额 == 项目: 身体 = body_l[计数] get_company_id = body.split("客户 ID:", 1)[1][4:10].strip() 别的: amount_ack_missing_l.append(金额) logging.info("缺失" + str(数量)) print("缺少" + str(数量))
使用 AgentJRock 代码:
当我 print(icl_dollar_amount[i]) 和 missing_amount[i] 时,我的 if 语句从不运行,只有 else 运行。但两个列表的值相同,请参见下文。
for i in range(len(missing_amount)):
print("Missing Amount : ", missing_amount[i])
print("ICL DOLLAR", icl_dollar_amount_l[i])
if missing_amount[i] == icl_dollar_amount_l[i]:
body = body_l[i]
get_company_id = body.split("Customer Id:", 1)[1][4:10].strip()
else:
amount_ack_missing_l.append(missing_amount[i])
logging.info("Missing " + str(missing_amount[i]))
print("Missing " + str(missing_amount[i]))
打印(icl_dollar_amount[i]
ICL DOLLAR 2,760,127.58
ICL DOLLAR 325,845.84
打印(缺失金额[i])
Missing Amount : 325,845.84
Missing Amount : 2,760,127.58
【问题讨论】:
标签: python