try: total_counts[item['caption']] += item['classification_count'] except: total_counts[item['caption']] = item['classification_count'] # print(total_counts) for item in item_list: rate = item['classification_count'] / total_counts[item['caption']] data_rate = '%.2f' % rate item['rate'] = data_rate item['total_count'] = total_counts[item['caption']] # print(item) # for user_item in user_item_list: # print(user_item) # return item_list, user_item_list file_date = time.strftime( '%Y%m%d', time.localtime(time.time() - 24 * 60 * 60 * (delta - 1))) profile_item_col = ('data_date', 'user_type', 'caption', 'classification', 'classification_count', 'total_count', 'rate', 'crawl_time') profile_export_file = 's_sp_alipay_profile.{}'.format(file_date) op.data_write(profile_item_col, item_list, profile_export_file) user_item_col = ('data_date', 'user_type', 'component', 'component_count', 'total_count', 'rate', 'crawl_time') user_export_file = 's_sp_alipay_user_component.{}'.format(file_date) op.data_write(user_item_col, user_item_list, user_export_file) time.sleep(3)
'./div[@class="ant-col-20 sync-success item-value"]' ).text except: v = div.find_element_by_xpath( './div[@class="ant-col-20 sync-error item-value"]' ).text item[k] = v crawl_time = time.strftime('%Y-%m-%d %H:00:00', time.localtime()) item['数据批次'] = crawl_time # time.sleep(5) item_list.append(item) driver.back() time.sleep(3) if driver.find_element_by_xpath( XPATH['marketing_activity']['next_page']).get_attribute( 'aria-disabled') == 'false': op.click(XPATH['marketing_activity']['next_page']) else: break item_cols = ('活动触发类型', '活动目标', '活动名称', '活动状态', '活动操作状态', '活动开始时间', '活动结束时间', '活动生效时间段', '奖品数量', '每人累计领取上限', '是否自主发奖', '温馨提示', '温馨提示正文', '人群分组', '主推产品', '适用产品交易方式', '定投周期', '已发放张数', '剩余可发放奖品数', '已恢复张数', '已核销张数', '活动编号', '礼包券模板ID', '红包模板Id', '红包发放个数', '红包核销个数', '核销率', '数据批次') op.data_write(item_cols, item_list, EXPORT_FILE['configure_export_file'])