modified: amazon/match_action.py
modified: amazon/price_match.py modified: config.py
This commit is contained in:
@@ -93,6 +93,7 @@ class AmzoneMatchAction(AmamzonBase):
|
|||||||
num = 0
|
num = 0
|
||||||
retry_num = 0
|
retry_num = 0
|
||||||
already_asin = set()
|
already_asin = set()
|
||||||
|
get_page_faild = 0
|
||||||
|
|
||||||
while retry_num < 3: # 最多重试3次
|
while retry_num < 3: # 最多重试3次
|
||||||
# if num > 3: #测试
|
# if num > 3: #测试
|
||||||
@@ -117,9 +118,13 @@ class AmzoneMatchAction(AmamzonBase):
|
|||||||
else:
|
else:
|
||||||
total_page = 0
|
total_page = 0
|
||||||
print(f"【{self.mark_name}】当前页码: {current_page} / 总页数: {total_page}")
|
print(f"【{self.mark_name}】当前页码: {current_page} / 总页数: {total_page}")
|
||||||
|
get_page_faild = 0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"【{self.mark_name}】获取页码失败", e)
|
print(f"【{self.mark_name}】获取页码失败", e)
|
||||||
|
get_page_faild+= 1
|
||||||
|
if get_page_faild > 2:
|
||||||
|
show_notification(f"【{self.mark_name}】获取页码失败超3次停止任务!")
|
||||||
|
break
|
||||||
|
|
||||||
sku_ls = self.tab.eles("xpath://div[@data-sku]",timeout=10)
|
sku_ls = self.tab.eles("xpath://div[@data-sku]",timeout=10)
|
||||||
print(f"【{self.mark_name}】获取到 {len(sku_ls)}")
|
print(f"【{self.mark_name}】获取到 {len(sku_ls)}")
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from config import runing_task, runing_shop
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from amazon.del_brand import AmamzonBase, kill_process
|
from DrissionPage import Chromium, ChromiumOptions
|
||||||
|
|
||||||
|
from amazon.del_brand import AmamzonBase, kill_process
|
||||||
from amazon.tool import show_notification,get_shop_info
|
from amazon.tool import show_notification,get_shop_info
|
||||||
|
|
||||||
|
from config import runing_task, runing_shop,base_dir
|
||||||
|
|
||||||
|
|
||||||
class ChromeAmzone:
|
class ChromeAmzone:
|
||||||
|
|
||||||
mark_name = "亚马逊详情采集"
|
mark_name = "亚马逊详情采集"
|
||||||
country_info = {
|
country_info = {
|
||||||
"英国": {
|
"英国": {
|
||||||
@@ -43,21 +46,46 @@ class ChromeAmzone:
|
|||||||
os.system('taskkill /f /t /im chrome.exe')
|
os.system('taskkill /f /t /im chrome.exe')
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# 使用 DrissionPage 启动浏览器(使用默认用户数据)
|
|
||||||
from DrissionPage import Chromium, ChromiumOptions
|
|
||||||
print("正在启动Chrome浏览器...")
|
print("正在启动Chrome浏览器...")
|
||||||
|
# sellersprite_plug_path = os.path.join(base_dir,"app_resource","sellersprite-extension-mv3")
|
||||||
|
sellersprite_plug_path = os.path.join("D:\\私单交付\\maixiang_AI\\","app_resource","sellersprite-extension-mv3")
|
||||||
|
print(sellersprite_plug_path)
|
||||||
# 配置浏览器选项
|
# 配置浏览器选项
|
||||||
co = ChromiumOptions()
|
co = ChromiumOptions()
|
||||||
|
# co.use_system_user_path(on_off=True)
|
||||||
|
co.set_user_data_path(r"D:\私单交付\maixiang_AI\user_data\chrome_data")
|
||||||
|
co.set_local_port(port=19890)
|
||||||
|
co.add_extension(sellersprite_plug_path)
|
||||||
|
# co.set_argument('--disable-features=DisableLoadExtensionCommandLineSwitch')
|
||||||
|
# co.set_argument('--load-extension',sellersprite_plug_path)
|
||||||
|
co.set_browser_path(r'D:\私单交付\maixiang_AI\app_resource\chrome-win\chrome.exe')
|
||||||
|
|
||||||
# 使用系统默认的用户数据目录
|
# 使用系统默认的用户数据目录
|
||||||
# co.set_user_data_path(r'C:\Users\{}\AppData\Local\Google\Chrome\User Data'.format(os.getenv('USERNAME')))
|
# co.set_user_data_path(r'C:\Users\{}\AppData\Local\Google\Chrome\User Data'.format(os.getenv('USERNAME')))
|
||||||
|
|
||||||
self.browser = Chromium(co)
|
self.browser = Chromium(co)
|
||||||
self.tab = self.browser.latest_tab
|
self.tab = self.browser.latest_tab
|
||||||
print("Chrome浏览器启动成功")
|
print("Chrome浏览器启动成功")
|
||||||
|
|
||||||
def accept_cookie(self):
|
def close_init_popup(self):
|
||||||
pass
|
"""
|
||||||
|
关闭所有的初始化弹窗
|
||||||
|
"""
|
||||||
|
self.tab.wait.doc_loaded(timeout=60,raise_err=True)
|
||||||
|
footbar = self.tab.eles('xpath://footer[@class="el-dialog__footer"]',timeout=5)
|
||||||
|
if len(footbar) > 0:
|
||||||
|
do_not_remind = footbar[0].eles('xpath:.//input[@class="el-checkbox__original"]')
|
||||||
|
if len(do_not_remind) > 0:
|
||||||
|
do_not_remind[0].check()
|
||||||
|
resume_immediately = footbar[0].eles('xpath:.//button')
|
||||||
|
if len(resume_immediately) > 0:
|
||||||
|
resume_immediately[0].click()
|
||||||
|
|
||||||
|
self.tab.wait.doc_loaded(timeout=60,raise_err=True)
|
||||||
|
accept_btn = self.tab.eles('xpath://input[@id="sp-cc-accept"]',timeout=10)
|
||||||
|
if len(accept_btn) > 0:
|
||||||
|
accept_btn[0].click()
|
||||||
|
|
||||||
|
|
||||||
def run(self, country, asin):
|
def run(self, country, asin):
|
||||||
"""
|
"""
|
||||||
@@ -98,6 +126,9 @@ class ChromeAmzone:
|
|||||||
# 2. 切换国家/设置邮编
|
# 2. 切换国家/设置邮编
|
||||||
print(f"正在检查并设置邮编: {zip_code}")
|
print(f"正在检查并设置邮编: {zip_code}")
|
||||||
self._set_zip_code(zip_code)
|
self._set_zip_code(zip_code)
|
||||||
|
|
||||||
|
self.close_init_popup()
|
||||||
|
|
||||||
|
|
||||||
# 3. 抓取数据
|
# 3. 抓取数据
|
||||||
print("正在抓取商品数据...")
|
print("正在抓取商品数据...")
|
||||||
@@ -317,14 +348,14 @@ if __name__ == '__main__':
|
|||||||
print(f"采集成功: {result1}")
|
print(f"采集成功: {result1}")
|
||||||
|
|
||||||
# 示例2:采集德国站点的商品信息
|
# 示例2:采集德国站点的商品信息
|
||||||
print("\n示例2:采集德国站点商品")
|
# print("\n示例2:采集德国站点商品")
|
||||||
result2 = chrome.run(country="德国", asin="B0CC8CW9G2")
|
# result2 = chrome.run(country="德国", asin="B0CC8CW9G2")
|
||||||
if result2:
|
# if result2:
|
||||||
print(f"采集成功: {result2}")
|
# print(f"采集成功: {result2}")
|
||||||
|
|
||||||
# 关闭浏览器
|
# # 关闭浏览器
|
||||||
print("\n正在关闭浏览器...")
|
# print("\n正在关闭浏览器...")
|
||||||
chrome.close()
|
# chrome.close()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"运行出错: {traceback.format_exc()}")
|
print(f"运行出错: {traceback.format_exc()}")
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ os.environ['APP_UPDATE_URL'] = APP_UPDATE_URL
|
|||||||
# 队列
|
# 队列
|
||||||
JSON_TASK_QUEUE = Queue()
|
JSON_TASK_QUEUE = Queue()
|
||||||
|
|
||||||
|
|
||||||
|
base_dir = os.getcwd()
|
||||||
|
|
||||||
#删除品牌,正在执行中的任务
|
#删除品牌,正在执行中的任务
|
||||||
runing_task = {
|
runing_task = {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user