This commit is contained in:
dylan 2022-10-02 23:22:38 +08:00
parent ae95af0e81
commit b659c764b8
1 changed files with 79 additions and 66 deletions

View File

@ -238,19 +238,31 @@ def sunbw(N, opts=None):
'//*[@id="main"]/div[2]/div[2]/table') '//*[@id="main"]/div[2]/div[2]/table')
opts['logger'].debug('Count of fetched order data: %d', len(elems)) opts['logger'].debug('Count of fetched order data: %d', len(elems))
Order_data.extend(elems) Order_data.extend(elems)
opts['logger'].info(f"当前共有{N['待评价订单']}个需要评价晒单。")
opts['logger'].info(f"当前共有{N['待评价订单']}个评价。")
opts['logger'].debug('Commenting on items') opts['logger'].debug('Commenting on items')
for i, Order in enumerate(Order_data): for i, Order in enumerate(Order_data):
if i + 1 > 10: if i + 1 > 10:
opts['logger'].info(f'\t已评价10个订单跳出') opts['logger'].info(f'\t已评价10个订单跳出')
break break
oname = Order.xpath( try:
'tr[@class="tr-bd"]/td[1]/div[1]/div[2]/div/a/text()')[0]
pid = Order.xpath(
'tr[@class="tr-bd"]/td[1]/div[1]/div[2]/div/a/@href')[0].replace('//item.jd.com/', '').replace('.html', '')
oid = Order.xpath('tr[@class="tr-th"]/td/span[3]/a/text()')[0] oid = Order.xpath('tr[@class="tr-th"]/td/span[3]/a/text()')[0]
#print (oname,oid,pid) opts['logger'].debug('oid: %s', oid)
#sys.exit() oname_data = Order.xpath(
'tr[@class="tr-bd"]/td[1]/div[1]/div[2]/div/a/text()')
opts['logger'].debug('oname_data: %s', oname_data)
pid_data = Order.xpath(
'tr[@class="tr-bd"]/td[1]/div[1]/div[2]/div/a/@href')
opts['logger'].debug('pid_data: %s', pid_data)
except IndexError:
opts['logger'].warning(f"{i + 1}个订单未查找到商品,跳过。")
continue
loop_times1 = min(len(oname_data), len(pid_data))
opts['logger'].debug('Commenting on orders')
opts['logger'].debug('Total loop times: %d', loop_times1)
idx = 0
for oname, pid in zip(oname_data, pid_data):
pid = pid.replace('//item.jd.com/', '').replace('.html', '')
opts['logger'].info(f'\t开始第{i+1}个订单: {oid}') opts['logger'].info(f'\t开始第{i+1}个订单: {oid}')
opts['logger'].debug('pid: %s', pid) opts['logger'].debug('pid: %s', pid)
opts['logger'].debug('oid: %s', oid) opts['logger'].debug('oid: %s', oid)
@ -310,12 +322,13 @@ def sunbw(N, opts=None):
opts['logger'].debug('Data: %s', data) opts['logger'].debug('Data: %s', data)
if not opts.get('dry_run'): if not opts.get('dry_run'):
opts['logger'].debug('Sending comment request') opts['logger'].debug('Sending comment request')
req_url2 = requests.post(url2, data=data, headers=headers) pj2 = requests.post(url2, headers=headers, data=data)
else: else:
opts['logger'].debug('Skipped sending comment request in dry run') opts['logger'].debug(
opts['logger'].info('完成') 'Skipped sending comment request in dry run')
opts['logger'].debug('Sleep time (s): %.1f', SUNBW_SLEEP_SEC) opts['logger'].debug('Sleep time (s): %.1f', ORDINARY_SLEEP_SEC)
time.sleep(SUNBW_SLEEP_SEC) time.sleep(ORDINARY_SLEEP_SEC)
idx += 1
N['待评价订单'] -= 1 N['待评价订单'] -= 1
return N return N