modified: amazon/__pycache__/approve.cpython-39.pyc
modified: amazon/__pycache__/del_brand.cpython-39.pyc modified: amazon/__pycache__/match_action.cpython-39.pyc modified: amazon/approve.py modified: amazon/del_brand.py modified: amazon/match_action.py new file: amazon/price_match.py modified: main.py
This commit is contained in:
@@ -2,6 +2,7 @@ import time
|
||||
import re
|
||||
import traceback
|
||||
from DrissionPage._pages.chromium_tab import ChromiumTab
|
||||
import pyautogui
|
||||
|
||||
from config import runing_task, runing_shop
|
||||
from datetime import datetime
|
||||
@@ -86,10 +87,11 @@ class AmzoneApprove(AmamzonBase):
|
||||
def wait_loaded(self):
|
||||
# 等待加载完成
|
||||
try:
|
||||
load_ele = self.tab.ele(
|
||||
load_ele = self.tab.eles(
|
||||
'xpath://kat-panel[@data-testid="kat-panel-ActionPanelContent"]//div[contains(@class,"Loader-module__loader")]|//kat-panel[@data-testid="kat-panel-ActionPanelContent"]/div[@data-f1-component]//div[contains(@class,"==")]/div[contains(@class,"==")]/span',
|
||||
timeout=3)
|
||||
load_ele.wait.deleted(timeout=5, raise_err=False)
|
||||
if len(load_ele) > 0:
|
||||
load_ele[0].wait.deleted(timeout=5, raise_err=False)
|
||||
except Exception as e:
|
||||
print("等待加载中消失出错", e)
|
||||
|
||||
@@ -106,67 +108,317 @@ class AmzoneApprove(AmamzonBase):
|
||||
print("当前操作的tab_id",self.tab.tab_id)
|
||||
self.browser.close_tabs(close_tab)
|
||||
|
||||
def handle_repair_product(self,tab:ChromiumTab):
|
||||
def wait_loaded():
|
||||
# def handle_repair_product_old(self,tab:ChromiumTab):
|
||||
# def wait_loaded():
|
||||
# # 等待加载完成
|
||||
# try:
|
||||
# load_ele = tab.ele(
|
||||
# 'xpath://div[@class="contentWrapper"]//div[contains(@class,"==")]/span[not(node())]',
|
||||
# timeout=3)
|
||||
# load_ele.wait.deleted(timeout=5, raise_err=False)
|
||||
# except Exception as e:
|
||||
# print("等待加载中消失出错", e)
|
||||
|
||||
# tab.wait.doc_loaded(timeout=60,raise_err=False)
|
||||
# submit_btn_ls = tab.eles('xpath://div[@id="ahd-product-policies-table"]/div//div[@data-testid="nextStepsMetricWrapper"]//kat-button[@label="提交"]',timeout=10)
|
||||
# if len(submit_btn_ls) == 0:
|
||||
# print("未找到提交按钮,可能页面未加载完成或者页面结构发生变化")
|
||||
# # return
|
||||
# for _ in range(3):
|
||||
# try:
|
||||
# # todo 遍历
|
||||
# for index in range(len(submit_btn_ls)):
|
||||
# if index > len(submit_btn_ls)-1:
|
||||
# print("提交按钮数量发生变化,停止处理")
|
||||
# break
|
||||
|
||||
# submit_btn = submit_btn_ls[index]
|
||||
|
||||
# # 关闭按钮
|
||||
# close_x_btn = tab.eles('xpath://div[@class="flyoutPanelContent"]/span',timeout=5)
|
||||
# if len(close_x_btn) > 0:
|
||||
# close_x_btn[0].wait.displayed(timeout=5, raise_err=False)
|
||||
# close_x_btn[0].click()
|
||||
|
||||
# submit_btn.wait.enabled(timeout=5, raise_err=False)
|
||||
# submit_btn.click()
|
||||
# time.sleep(0.5)
|
||||
# self.wait_loaded()
|
||||
|
||||
# wait_loaded()
|
||||
|
||||
# need_input = tab.eles('xpath://div[@class="contentWrapper"]//kat-input[@data-testid="kat-input-dew:ump_epr_resgitration_number_title"]',timeout=5)
|
||||
# if len(need_input) > 0:
|
||||
# print("需要输入注册号,不符合操作要求,跳过...")
|
||||
# continue
|
||||
|
||||
# target_title = tab.eles('xpath://div[@class="contentWrapper"]//section//h4[text()="警告和安全信息"]')
|
||||
# if len(target_title) > 0:
|
||||
# not_start = tab.eles('xpath://div[@class="contentWrapper"]//div[@aria-label="安全证明"]//kat-label[@text="未开始"]')
|
||||
# if len(not_start) == 0:
|
||||
# print("安全证明-不是未开始状态,不需要操作")
|
||||
# continue
|
||||
|
||||
# not_start.wait.displayed(timeout=5, raise_err=False)
|
||||
# not_start.click()
|
||||
|
||||
# wait_loaded()
|
||||
|
||||
# check = tab.ele('xpath://div[@class="contentWrapper"]//kat-checkbox[@name="value"]')
|
||||
# check.wait.displayed(timeout=5, raise_err=False)
|
||||
# check.click()
|
||||
|
||||
# save_btn = tab.ele('xpath://div[@class="contentWrapper"]//kat-button[@variant="primary"]')
|
||||
# save_btn.wait.enabled(timeout=5, raise_err=False)
|
||||
# save_btn.click()
|
||||
|
||||
# wait_loaded()
|
||||
|
||||
# close_btn = tab.ele('xpath://div[@class="contentWrapper"]//kat-button[@label="关闭"]',timeout=10)
|
||||
# close_btn.wait.displayed(timeout=5, raise_err=False)
|
||||
# close_btn.click()
|
||||
|
||||
# save_btn_ls = tab.eles('xpath://div[@class="contentWrapper"]//kat-button[@variant="primary"]',timeout=5)
|
||||
# if len(save_btn_ls) > 0:
|
||||
# option_selection_ls = tab.eles('xpath://div[@class="contentWrapper"]//div[@role="option"]',timeout=5)
|
||||
# for option in option_selection_ls:
|
||||
# option.click()
|
||||
# time.sleep(0.5)
|
||||
|
||||
# save_btn_ls[0].wait.enabled(timeout=5, raise_err=False)
|
||||
# save_btn_ls[0].click()
|
||||
|
||||
# wait_loaded()
|
||||
|
||||
# close_btn = tab.ele('xpath://div[@class="contentWrapper"]//kat-button[@label="关闭"]',timeout=10)
|
||||
# close_btn.wait.displayed(timeout=5, raise_err=False)
|
||||
# close_btn.wait.enabled(timeout=5, raise_err=False)
|
||||
# close_btn.click()
|
||||
|
||||
# submit_btn_ls = tab.eles('xpath://div[@id="ahd-product-policies-table"]/div//div[@data-testid="nextStepsMetricWrapper"]//kat-button[@label="提交"]',timeout=10)
|
||||
# break
|
||||
# except Exception as e:
|
||||
# print(f"【handle_repair_product】处理修复商品信息异常", traceback.format_exc())
|
||||
# tab.refresh()
|
||||
# tab.wait.doc_loaded(timeout=60,raise_err=False)
|
||||
# time.sleep(2)
|
||||
|
||||
# print("修复商品信息处理完成!")
|
||||
# tab.close()
|
||||
|
||||
def handle_repair_product(self,tab:ChromiumTab,headle_type=""):
|
||||
def wait_loaded(wait_type="contentWrapper"):
|
||||
# 等待加载完成
|
||||
try:
|
||||
load_ele = tab.ele(
|
||||
'xpath://div[@class="contentWrapper"]//div[contains(@class,"==")]/span[not(node())]',
|
||||
timeout=3)
|
||||
load_ele.wait.deleted(timeout=5, raise_err=False)
|
||||
except Exception as e:
|
||||
print("等待加载中消失出错", e)
|
||||
print("------------【修复商品信息】等待加载完成-----------------")
|
||||
for _ in range(3):
|
||||
try:
|
||||
load_ele = tab.eles(
|
||||
'xpath://div[@class="contentWrapper"]//div[contains(@class,"==")]/span[not(node())]|//kat-spinner[@id="ahd-app-page-spinner"]',
|
||||
timeout=10)
|
||||
if len(load_ele) > 0:
|
||||
load_ele[0].wait.deleted(timeout=20, raise_err=False)
|
||||
if wait_type == "contentWrapper":
|
||||
contentWrapper = tab.eles('xpath://div[@class="contentWrapper"]//h4',timeout=20)
|
||||
if len(contentWrapper) > 0:
|
||||
contentWrapper[0].wait.displayed(timeout=20, raise_err=True)
|
||||
break
|
||||
else:
|
||||
time.sleep(2)
|
||||
break
|
||||
if wait_type == "content":
|
||||
contentWrapper = tab.eles('xpath://div[@class="contentWrapper"]',timeout=20)
|
||||
if len(contentWrapper) > 0:
|
||||
contentWrapper[0].wait.displayed(timeout=20, raise_err=True)
|
||||
break
|
||||
else:
|
||||
time.sleep(2)
|
||||
break
|
||||
if wait_type == "section":
|
||||
section = tab.eles('xpath://section[@class="ahd-product-policy__section"]',timeout=20)
|
||||
if len(section) > 0:
|
||||
section[0].wait.displayed(timeout=20, raise_err=True)
|
||||
break
|
||||
except Exception as e:
|
||||
print("等待加载中消失出错", e)
|
||||
print("-----------------------------")
|
||||
|
||||
def close_contentWrapper():
|
||||
# 关闭按钮
|
||||
# close_x_btn = tab.eles('xpath://div[@class="flyoutPanelContent"]/span',timeout=5)
|
||||
# if len(close_x_btn) > 0:
|
||||
# close_x_btn[0].wait.displayed(timeout=5, raise_err=False)
|
||||
# close_x_btn[0].click()
|
||||
# time.sleep(1)
|
||||
# close_x_btn[0].wait.deleted(timeout=5, raise_err=False)
|
||||
close_x_btn = tab.eles('xpath://div[@class="flyoutPanelContent"]/span',timeout=5)
|
||||
contentWrapper = tab.eles('xpath://div[@class="flyoutPanelContent"]/div[@class="contentWrapper"]',timeout=5)
|
||||
if len(close_x_btn) > 0 and len(contentWrapper)>0 :
|
||||
if len(contentWrapper[0].children()) > 0:
|
||||
close_x_btn[0].wait.displayed(timeout=5, raise_err=False)
|
||||
close_x_btn[0].click()
|
||||
|
||||
tab.wait.doc_loaded(timeout=60,raise_err=False)
|
||||
submit_btn_ls = tab.eles('xpath://div[@id="ahd-product-policies-table"]/div//div[@data-testid="nextStepsMetricWrapper"]//kat-button[@label="提交"]',timeout=10)
|
||||
if len(submit_btn_ls) == 0:
|
||||
print("未找到提交按钮,可能页面未加载完成或者页面结构发生变化")
|
||||
|
||||
wait_loaded(wait_type="section")
|
||||
# product_policy = tab.eles('xpath://div[@data-testid="ahd-desktop-product-policy"]')
|
||||
product_policy = tab.eles('xpath://div[@data-testid="ahd-desktop-product-policy" and @class="ahd-product-policy-table-row-wrapper"]|//div[@class="ahd-product-policy-table-row-wrapper-nested" and @data-testid="ahd-desktop-product-policy"]')
|
||||
if len(product_policy) == 0:
|
||||
print("未找到提交处理区域,可能页面未加载完成或者页面结构发生变化")
|
||||
time.sleep(5)
|
||||
# product_policy = tab.eles('xpath://div[@data-testid="ahd-desktop-product-policy"]')
|
||||
product_policy = tab.eles('xpath://div[@data-testid="ahd-desktop-product-policy" and @class="ahd-product-policy-table-row-wrapper"]|//div[@class="ahd-product-policy-table-row-wrapper-nested" and @data-testid="ahd-desktop-product-policy"]')
|
||||
|
||||
print("等待5秒后再次查找提交处理区域:",len(product_policy))
|
||||
|
||||
# submit_btn_ls = tab.eles('xpath://div[@id="ahd-product-policies-table"]/div//div[@data-testid="nextStepsMetricWrapper"]//kat-button[@label="提交"]',timeout=10)
|
||||
# if len(submit_btn_ls) == 0:
|
||||
# return
|
||||
now_index = 0
|
||||
submit_index = 0
|
||||
for _ in range(3):
|
||||
try:
|
||||
# 先全部点开
|
||||
chevron_right_ls = tab.eles('xpath://kat-icon[@name="chevron-right"]',timeout=10)
|
||||
for ele in chevron_right_ls:
|
||||
ele.click()
|
||||
time.sleep(0.5)
|
||||
except Exception as e:
|
||||
print("【修复商品信息】全部点开失败",e)
|
||||
try:
|
||||
# todo 遍历
|
||||
for index in range(len(submit_btn_ls)):
|
||||
if index > len(submit_btn_ls)-1:
|
||||
print("提交按钮数量发生变化,停止处理")
|
||||
print("【商品修复产品卡片】数量",len(product_policy))
|
||||
print("【商品修复产品卡片】列表",product_policy)
|
||||
for index in range(now_index,len(product_policy)):
|
||||
product_policy = tab.eles('xpath://div[@data-testid="ahd-desktop-product-policy" and @class="ahd-product-policy-table-row-wrapper"]|//div[@class="ahd-product-policy-table-row-wrapper-nested" and @data-testid="ahd-desktop-product-policy"]')
|
||||
now_index = index
|
||||
if index > len(product_policy)-1:
|
||||
print("提交按钮区域发生变化,停止处理")
|
||||
break
|
||||
message_link = product_policy[index].eles('xpath:.//a[@data-testid="ahd-reason-message-link"]')
|
||||
message = message_link[0].text
|
||||
|
||||
submit_btn = submit_btn_ls[index]
|
||||
if headle_type in ['查看冻结原因']:
|
||||
need_heanle = any(i in message for i in ["制造商详细联系信息","警告和安全信息","负责人详细联系信息"])
|
||||
else:
|
||||
need_heanle = True
|
||||
|
||||
if not need_heanle:
|
||||
print(f"【{headle_type}】【{message}】不需要处理,跳过")
|
||||
continue
|
||||
|
||||
spread_btn = product_policy[index].eles('xpath:.//kat-icon[@name="chevron-right"]',timeout=5)
|
||||
print(f"{index},是否存在展开按钮",len(spread_btn))
|
||||
if len(spread_btn) > 0:
|
||||
spread_btn[0].click()
|
||||
time.sleep(0.5)
|
||||
|
||||
submit_btn_ls = product_policy[index].eles('xpath:.//kat-button[@label="提交"]',timeout=5)
|
||||
# try:
|
||||
# submit_btn = product_policy[index].ele('xpath:.//kat-button[@label="提交"]',timeout=5)
|
||||
# except Exception as e:
|
||||
# print(datetime.now().strftime("%Y-%m-%d %H:%M:%S") ,"没有查找到提交按钮,跳过!")
|
||||
# close_contentWrapper()
|
||||
# continue
|
||||
# print("提交按钮数量:",len(submit_btn))
|
||||
print("提交按钮列表:",submit_btn_ls)
|
||||
if len(submit_btn_ls) > 0:
|
||||
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"),"查找到提交按钮")
|
||||
# submit_btn = submit_btn[0]
|
||||
submit_btn = tab.eles('xpath://kat-button[@label="提交"]',timeout=10)[submit_index]
|
||||
submit_index += 1
|
||||
else:
|
||||
print(datetime.now().strftime("%Y-%m-%d %H:%M:%S") ,"没有查找到提交按钮,跳过!")
|
||||
close_contentWrapper()
|
||||
continue
|
||||
# time.sleep(10)
|
||||
# 关闭按钮
|
||||
close_x_btn = tab.eles('xpath://div[@class="flyoutPanelContent"]/span',timeout=5)
|
||||
if len(close_x_btn) > 0:
|
||||
close_x_btn[0].wait.displayed(timeout=5, raise_err=False)
|
||||
close_x_btn[0].click()
|
||||
contentWrapper = tab.eles('xpath://div[@class="flyoutPanelContent"]/div[@class="contentWrapper"]',timeout=5)
|
||||
if len(close_x_btn) > 0 and len(contentWrapper)>0 :
|
||||
if len(contentWrapper[0].children()) > 0:
|
||||
close_x_btn[0].wait.displayed(timeout=5, raise_err=False)
|
||||
close_x_btn[0].click()
|
||||
|
||||
print("开始操作",submit_btn)
|
||||
print("操作的ID 为:",submit_btn.attr('id'))
|
||||
submit_btn.wait.enabled(timeout=5, raise_err=False)
|
||||
submit_btn.click()
|
||||
time.sleep(0.5)
|
||||
self.wait_loaded()
|
||||
|
||||
# 先直接等待contentWrapper出现,不要进行复杂的元素查找
|
||||
try:
|
||||
# 使用简单的等待,避免触发页面事件
|
||||
for check_count in range(10):
|
||||
contentWrapper_exists = tab.eles('xpath://div[@class="contentWrapper"]', timeout=2)
|
||||
if len(contentWrapper_exists) > 0:
|
||||
print(f"【弹窗已出现】第{check_count+1}次检查")
|
||||
time.sleep(2) # 再等待2秒让内容完全加载
|
||||
break
|
||||
time.sleep(1)
|
||||
except Exception as e:
|
||||
print(f"等待弹窗出现异常: {e}")
|
||||
|
||||
# wait_loaded(wait_type="content")
|
||||
|
||||
for j in range(4):
|
||||
if j == 0:
|
||||
timeout = 5
|
||||
else:
|
||||
timeout = 10
|
||||
contentWrapper = tab.eles('xpath://div[@class="contentWrapper"]//h4',timeout=timeout)
|
||||
print("标题的数量",len(contentWrapper))
|
||||
if len(contentWrapper) > 0:
|
||||
contentWrapper[0].wait.displayed(timeout=20, raise_err=True)
|
||||
break
|
||||
else:
|
||||
# 关闭按钮
|
||||
close_contentWrapper()
|
||||
time.sleep(2)
|
||||
submit_btn.click()
|
||||
|
||||
wait_loaded()
|
||||
|
||||
need_input = tab.eles('xpath://div[@class="contentWrapper"]//kat-input[@data-testid="kat-input-dew:ump_epr_resgitration_number_title"]',timeout=5)
|
||||
if len(need_input) > 0:
|
||||
print("需要输入注册号,不符合操作要求,跳过...")
|
||||
close_contentWrapper()
|
||||
continue
|
||||
|
||||
target_title = tab.eles('xpath://div[@class="contentWrapper"]//section//h4[text()="警告和安全信息"]')
|
||||
target_title = tab.eles('xpath://div[@class="contentWrapper"]//section//h4[text()="警告和安全信息"]',timeout=10)
|
||||
print(f"序号{index}【警告和安全信息】数量 ->",len(target_title))
|
||||
if len(target_title) > 0:
|
||||
not_start = tab.eles('xpath://div[@class="contentWrapper"]//div[@aria-label="安全证明"]//kat-label[@text="未开始"]')
|
||||
if len(not_start) == 0:
|
||||
print("安全证明-不是未开始状态,不需要操作")
|
||||
is_Continue = False
|
||||
for j in range(10):
|
||||
not_start = tab.eles('xpath://div[@class="contentWrapper"]//div[@aria-label="安全证明"]//kat-label',timeout=2)
|
||||
if len(not_start) > 0:
|
||||
status_lebel = not_start[0].attr("text")
|
||||
print(f"序号{index}【警告和安全信息】状态 ->",status_lebel)
|
||||
if status_lebel and str(status_lebel).strip() != "" and status_lebel != "未开始":
|
||||
print("安全证明-不是未开始状态,不需要操作")
|
||||
close_contentWrapper()
|
||||
continue
|
||||
if status_lebel == "未开始":
|
||||
is_Continue = True
|
||||
break
|
||||
else:
|
||||
time.sleep(1)
|
||||
# not_start = tab.eles('xpath://div[@class="contentWrapper"]//div[@aria-label="安全证明"]//kat-label[@text="未开始"]',timeout=10)
|
||||
# if len(not_start) == 0:
|
||||
# print("安全证明-不是未开始状态,不需要操作")
|
||||
# close_contentWrapper()
|
||||
# continue
|
||||
print(f"序号{index}【警告和安全信息】是否需要继续 ->",is_Continue)
|
||||
if not is_Continue:
|
||||
continue
|
||||
|
||||
not_start = not_start[0]
|
||||
not_start.wait.displayed(timeout=5, raise_err=False)
|
||||
not_start.click()
|
||||
|
||||
wait_loaded()
|
||||
|
||||
check = tab.ele('xpath://div[@class="contentWrapper"]//kat-checkbox[@name="value"]')
|
||||
check = tab.ele('xpath://div[@class="contentWrapper"]//kat-checkbox[@name="value"]',timeout=10)
|
||||
check.wait.displayed(timeout=5, raise_err=False)
|
||||
check.click()
|
||||
|
||||
save_btn = tab.ele('xpath://div[@class="contentWrapper"]//kat-button[@variant="primary"]')
|
||||
save_btn = tab.ele('xpath://div[@class="contentWrapper"]//kat-button[@variant="primary"]',timeout=10)
|
||||
save_btn.wait.enabled(timeout=5, raise_err=False)
|
||||
save_btn.click()
|
||||
|
||||
@@ -175,8 +427,11 @@ class AmzoneApprove(AmamzonBase):
|
||||
close_btn = tab.ele('xpath://div[@class="contentWrapper"]//kat-button[@label="关闭"]',timeout=10)
|
||||
close_btn.wait.displayed(timeout=5, raise_err=False)
|
||||
close_btn.click()
|
||||
print(f"序号{index}【警告和安全信息】操作完成")
|
||||
continue
|
||||
|
||||
save_btn_ls = tab.eles('xpath://div[@class="contentWrapper"]//kat-button[@variant="primary"]',timeout=5)
|
||||
save_btn_ls = tab.eles('xpath://div[@class="contentWrapper"]//kat-button[@variant="primary"]',timeout=10)
|
||||
print(f"序号{index}【选择保存】是否存在->",len(save_btn_ls))
|
||||
if len(save_btn_ls) > 0:
|
||||
option_selection_ls = tab.eles('xpath://div[@class="contentWrapper"]//div[@role="option"]',timeout=5)
|
||||
for option in option_selection_ls:
|
||||
@@ -187,29 +442,39 @@ class AmzoneApprove(AmamzonBase):
|
||||
save_btn_ls[0].click()
|
||||
|
||||
wait_loaded()
|
||||
close_contentWrapper()
|
||||
print(f"序号{index}【选择保存】操作完成")
|
||||
continue
|
||||
|
||||
close_btn = tab.ele('xpath://div[@class="contentWrapper"]//kat-button[@label="关闭"]',timeout=10)
|
||||
close_btn.wait.displayed(timeout=5, raise_err=False)
|
||||
close_btn.wait.enabled(timeout=5, raise_err=False)
|
||||
close_btn.click()
|
||||
|
||||
submit_btn_ls = tab.eles('xpath://div[@id="ahd-product-policies-table"]/div//div[@data-testid="nextStepsMetricWrapper"]//kat-button[@label="提交"]',timeout=10)
|
||||
if len(submit_btn_ls) > 0:
|
||||
submit_btn_ls[0].click()
|
||||
submit_btn_ls[0].wait.deleted(timeout=5, raise_err=False)
|
||||
wait_loaded()
|
||||
|
||||
close_contentWrapper()
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"【handle_repair_product】处理修复商品信息异常", traceback.format_exc())
|
||||
tab.refresh()
|
||||
tab.wait.doc_loaded(timeout=60,raise_err=False)
|
||||
time.sleep(2)
|
||||
wait_loaded(wait_type="section")
|
||||
# product_policy = tab.eles('xpath://div[@data-testid="ahd-desktop-product-policy"]')
|
||||
product_policy = tab.eles('xpath://div[@data-testid="ahd-desktop-product-policy" and @class="ahd-product-policy-table-row-wrapper"]|//div[@class="ahd-product-policy-table-row-wrapper-nested" and @data-testid="ahd-desktop-product-policy"]')
|
||||
|
||||
|
||||
print("修复商品信息处理完成!")
|
||||
tab.close()
|
||||
|
||||
|
||||
def run_page_action(self):
|
||||
print("开始执行")
|
||||
num = 0
|
||||
retry_num = 0
|
||||
already_asin = set()
|
||||
|
||||
now_page = None
|
||||
while retry_num < 3: # 最多重试3次
|
||||
# if num > 3: #测试
|
||||
# return
|
||||
@@ -235,20 +500,27 @@ class AmzoneApprove(AmamzonBase):
|
||||
print(f"当前页码: {current_page} / 总页数: {total_page}")
|
||||
except Exception as e:
|
||||
print("获取页码失败", e)
|
||||
|
||||
print("==========商品风险解决==============")
|
||||
|
||||
sku_ls = self.tab.eles("xpath://div[@data-sku]",timeout=10)
|
||||
print(f"获取到 {len(sku_ls)}")
|
||||
if len(sku_ls) == 0:
|
||||
print(f"搜索不出SKU停止")
|
||||
break
|
||||
# for sku_ele in sku_ls[0:2]:
|
||||
for sku_ele in sku_ls:
|
||||
for sku_ele in sku_ls[1:]:
|
||||
# solve_problem = sku_ele.eles('xpath:.//kat-link[@label="解决商品信息问题"]')
|
||||
|
||||
asin = sku_ele.ele('xpath:.//div[contains(@class,"JanusSplitBox-module__container")]//div[contains(@class,"JanusSplitBox-module__panel--") and contains(string(.),"ASIN")]/..//div[last()]').text
|
||||
print(f"*************** {asin} *****************")
|
||||
print(f"ASIN {asin} 存在问题,正在点击解决...")
|
||||
if asin in already_asin:
|
||||
print(f"{asin} 已经处理过了,跳过")
|
||||
continue
|
||||
solve_problem = sku_ele.eles('xpath:.//kat-link[@label="解决商品信息问题"]|.//kat-link[@label="修复被禁止显示的商品"]|.//kat-link[@label="解决商品移除风险"]')
|
||||
xp_ls = [f'.//kat-link[@label="{i}"]' for i in ["解决商品信息问题","修复被禁止显示的商品","解决商品移除风险","查看冻结原因"]]
|
||||
xp = "|".join(xp_ls)
|
||||
# solve_problem = sku_ele.eles('xpath:.//kat-link[@label="解决商品信息问题"]|.//kat-link[@label="修复被禁止显示的商品"]|.//kat-link[@label="解决商品移除风险"]')
|
||||
solve_problem = sku_ele.eles(f'xpath:{xp}')
|
||||
if len(solve_problem) == 0:
|
||||
# //a[text0=”添加缺失的商品详情”]
|
||||
lack_info = sku_ele.eles('xpath:.//a[text()="添加缺失的商品详情"]')
|
||||
@@ -264,6 +536,9 @@ class AmzoneApprove(AmamzonBase):
|
||||
|
||||
solve_problem[0].click()
|
||||
|
||||
label = solve_problem[0].attr('label')
|
||||
print("【当前类别】",label)
|
||||
|
||||
action_panel = self.tab.ele('xpath://kat-panel-wrapper[@data-testid="kat-panel-wrapper-ActionPanelContent"]')
|
||||
action_panel.wait.displayed(timeout=5, raise_err=False)
|
||||
|
||||
@@ -274,15 +549,34 @@ class AmzoneApprove(AmamzonBase):
|
||||
# 如果存在“请求批准”按钮,则直接返回跳过
|
||||
request_approval_btn = self.tab.eles('xpath://kat-panel-wrapper[@data-testid="kat-panel-wrapper-ActionPanelContent"]//div[@data-testid="section-header" and contains(string(.),"移除")]',timeout=5)
|
||||
if len(request_approval_btn) > 0:
|
||||
print(f"ASIN {asin} 存在请求批准按钮,不需要处理,跳过...")
|
||||
panel_close_btn = self.tab.ele('xpath://kat-panel[@data-testid="kat-panel-ActionPanelContent"]',
|
||||
timeout=5).sr('xpath:.//button[@class="close"]')
|
||||
panel_close_btn.click()
|
||||
# 新增"查看冻结原因" 的情况下,需要点击修复商品详情
|
||||
if "查看冻结原因" in label:
|
||||
repair_produ_btn_xp = '//kat-panel-wrapper[@data-testid="kat-panel-wrapper-ActionPanelContent"]//kat-button[@variant="secondary" and @class="action-button" and contains(string(.),"修复商品信息")]'
|
||||
repair_produ_btn = self.tab.eles(f'xpath:{repair_produ_btn_xp}',timeout=5)
|
||||
print(f"{asin}【查看冻结原因】修复商品信息数量",len(repair_produ_btn))
|
||||
if len(repair_produ_btn) > 0:
|
||||
print(f"{asin}【查看冻结原因】修复商品信息数量,开始操作")
|
||||
self.clear_tab()
|
||||
repair_produ_btn[0].click()
|
||||
time.sleep(3)
|
||||
# 获取最新的tab
|
||||
new_tab = self.browser.latest_tab
|
||||
if isinstance(new_tab, str):
|
||||
new_tab = self.browser.get_tab(id_or_num=new_tab)
|
||||
|
||||
action_panel.wait.deleted(timeout=3, raise_err=False)
|
||||
yield (asin,"请求批准")
|
||||
already_asin.add(asin)
|
||||
continue
|
||||
self.handle_repair_product(new_tab,headle_type="查看冻结原因")
|
||||
else:
|
||||
print(f"{i}【查看冻结原因】修复商品信息没有,不需要操作")
|
||||
else:
|
||||
print(f"ASIN {asin} 存在请求批准按钮,不需要处理,跳过...")
|
||||
panel_close_btn = self.tab.ele('xpath://kat-panel[@data-testid="kat-panel-ActionPanelContent"]',
|
||||
timeout=5).sr('xpath:.//button[@class="close"]')
|
||||
panel_close_btn.click()
|
||||
|
||||
action_panel.wait.deleted(timeout=3, raise_err=False)
|
||||
yield (asin,"请求批准")
|
||||
already_asin.add(asin)
|
||||
continue
|
||||
|
||||
# 无需采取任何操作
|
||||
not_operate = self.tab.eles('xpath://kat-alert[contains(@description,"如果您之前已提交更改,则这些更改当前正在处理中") and not(@dismissed)]',timeout=3)
|
||||
@@ -310,7 +604,7 @@ class AmzoneApprove(AmamzonBase):
|
||||
|
||||
# TODO 增加 “出现警告和安全信息时候下滑” 的情况
|
||||
safe_handle_ls = self.tab.eles('xpath://kat-panel[@data-testid="kat-panel-ActionPanelContent"]//div[@aria-label="安全证明"]//kat-label[@text="未开始"]',
|
||||
timeout=5)
|
||||
timeout=15)
|
||||
if len(safe_handle_ls) > 0:
|
||||
print("存在安全证明,正在处理...")
|
||||
safe_handle_ls[0].click()
|
||||
@@ -329,17 +623,19 @@ class AmzoneApprove(AmamzonBase):
|
||||
time.sleep(0.5)
|
||||
|
||||
# 点击保存
|
||||
confirm_btn = self.tab.ele('xpath://kat-panel-wrapper[@data-testid="kat-panel-wrapper-ActionPanelContent"]//kat-button[@variant="primary"]')
|
||||
confirm_btn.wait.displayed(timeout=3, raise_err=False)
|
||||
confirm_btn.click()
|
||||
confirm_btn = self.tab.eles('xpath://kat-panel-wrapper[@data-testid="kat-panel-wrapper-ActionPanelContent"]//kat-button[@variant="primary"]')
|
||||
if len(confirm_btn) > 0:
|
||||
confirm_btn[0].wait.displayed(timeout=3, raise_err=False)
|
||||
confirm_btn[0].click()
|
||||
|
||||
self.wait_loaded()
|
||||
|
||||
# 等待关闭按钮出现
|
||||
try:
|
||||
close_btn = self.tab.ele('xpath://kat-panel[@data-testid="kat-panel-ActionPanelContent"]//kat-button[@label="关闭"]',
|
||||
close_btn = self.tab.eles('xpath://kat-panel[@data-testid="kat-panel-ActionPanelContent"]//kat-button[@label="关闭"]',
|
||||
timeout=10)
|
||||
close_btn.click()
|
||||
if len(close_btn)>0:
|
||||
close_btn[0].click()
|
||||
except Exception as e:
|
||||
print("点击关闭按钮失败",e)
|
||||
|
||||
@@ -351,7 +647,7 @@ class AmzoneApprove(AmamzonBase):
|
||||
print(f"ASIN {asin} 存在修复商品信息按钮,正在点击...")
|
||||
self.clear_tab()
|
||||
repair_product[0].click()
|
||||
time.sleep(1)
|
||||
time.sleep(3)
|
||||
# 获取最新的tab
|
||||
new_tab = self.browser.latest_tab
|
||||
if isinstance(new_tab, str):
|
||||
@@ -366,6 +662,7 @@ class AmzoneApprove(AmamzonBase):
|
||||
|
||||
yield (asin,"处理完成")
|
||||
already_asin.add(asin)
|
||||
print(f"*********************{asin} 处理完成*************************")
|
||||
|
||||
try:
|
||||
# 全部操作完成,关闭
|
||||
@@ -556,6 +853,8 @@ class ApproveTask:
|
||||
items = data.get("items", [])
|
||||
country_codes = data.get("country_codes", [])
|
||||
risk_listing_filter = data.get("risk_listing_filter", "")
|
||||
# 测试
|
||||
# risk_listing_filter = "DetailPageRemoved" #data.get("risk_listing_filter", "")
|
||||
|
||||
if not task_id:
|
||||
self.log("任务ID为空,跳过", "WARNING")
|
||||
@@ -993,14 +1292,14 @@ if __name__ == '__main__':
|
||||
"username": "自动化_Robot",
|
||||
"password": "#20zsg25"
|
||||
}
|
||||
shop_name = "魏振峰"
|
||||
shop_name = "郭亚芳"
|
||||
country = "德国"
|
||||
kill_process('v6')
|
||||
driver = AmzoneApprove(user_info)
|
||||
browser = driver.open_shop(shop_name)
|
||||
sw_suc = driver.SwitchingCountries(country)
|
||||
driver.SwitchPage()
|
||||
risk_listing_filter = "ApprovalRequired"
|
||||
risk_listing_filter = "DetailPageRemoved"
|
||||
for _ in range(3):
|
||||
try:
|
||||
sku_ls = driver.search(filter_type=risk_listing_filter)
|
||||
|
||||
Reference in New Issue
Block a user