Commit 12889b6f authored by 邱阿朋's avatar 邱阿朋

feat(vc): 添加分页和筛选按钮点击自动化逻辑

- 在advert_cost模块增加__click_button方法,实现点击过滤和分页按钮流程
- 点击过滤条件中spend选项并应用,调整每页显示200条数据
- 实现分页按钮翻页逻辑,自动翻页直至按钮禁用停止
- 在run方法中调用分页点击功能,支持完整数据采集
- 修改login_check,增加"Two-Step Verification"验证码流程判断
- 修复super_gui模块调用processor的启动代码,启用run和push_data_queue函数调用
parent ac59430d
......@@ -3,6 +3,7 @@ import time
from lxml import etree
def switch_domain(country):
domain = "https://vendorcentral.amazon.com/"
......@@ -21,6 +22,7 @@ def switch_domain(country):
return domain
class LoginDomain:
def __init__(self, logger, page, country):
self.logger = logger
......@@ -30,7 +32,7 @@ class LoginDomain:
# 运行状态
self.running = False
def set_status(self,status):
def set_status(self, status):
self.running = status
def login_check(self):
......@@ -55,7 +57,11 @@ class LoginDomain:
self.logger.info("请登录账号")
continue
if title in ["Authentication required"]:
code_title = [
"Authentication required",
"Two-Step Verification"
]
if title in code_title:
self.logger.info("请输入图形验证码")
continue
......
......@@ -70,6 +70,57 @@ class AdvertCost(AutoInterface):
return results
def __click_button(self):
# 点击过滤按钮
option_selector = '#products_view:products_view:addFilterSelector:optionSelector'
self.page.wait.eles_loaded(option_selector)
self.page.ele(option_selector).click()
time.sleep(2)
# 点击spend选项
spend = '#products_view:products_view:addFilterSelector:option-spend'
self.page.wait.eles_loaded(spend)
self.page.ele(spend).click()
time.sleep(2)
# 点击应用
apply = '#products_view:products_view:filter:spend:apply'
self.page.wait.eles_loaded(apply) # 等待元素加载
self.page.ele(apply).click()
time.sleep(5)
# 点击分页按钮
dropdown = '#products_view:products_view:pagination-dropdown'
self.page.wait.eles_loaded(dropdown)
self.page.ele(dropdown).click()
time.sleep(1)
# 选择200条
dropdown200 = '#products_view:products_view:pagination-dropdown-200'
self.page.wait.eles_loaded(dropdown200)
self.page.ele(dropdown200).click()
time.sleep(5)
# 翻页
pagination_selector = '#products_view:products_view:pagination-next'
self.page.wait.eles_loaded(pagination_selector)
pagination_btn = self.page.ele(pagination_selector)
iteration = 0
while True:
# 检查 disabled 属性
if pagination_btn.attr('disabled') is None:
pagination_btn.click()
self.logger.debug(f"第 {iteration + 1} 页已点击,等待加载...")
# 等待页面加载完成
time.sleep(3)
self.page.wait.eles_loaded(pagination_selector, timeout=10)
iteration += 1
continue
else:
self.logger.debug("分页按钮已禁用,停止翻页")
break
def run(self, file_name: str):
self.__page_get("hz/vendor/members/advertising/home?ref_=vc_xx_subNav")
# wrapper_html = self.page.ele(". columns-wrapper a20m-columns-wrapper", timeout=5).html
......@@ -134,6 +185,9 @@ class AdvertCost(AutoInterface):
# 解析成 datetime转换成时间戳
self.select_day = int(datetime.strptime(date_str, "%b %d, %Y").timestamp())
# 点击分页按钮
self.__click_button()
# 点击导出
date_format = datetime.now().strftime('%Y%m%d%H%M')
file_name = f"products\\{date_format}-{name}.csv"
......
......@@ -192,8 +192,8 @@ class VCManagerGUI(ttk.Window):
self.processor = self._get_processor(action_value, country_value)
if self.processor:
self.processor.set_running(True)
# self.processor.run("")
# self.processor.push_data_queue()
self.processor.run("")
self.processor.push_data_queue()
self.logger.info("操作成功完成!")
except Exception as e:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment