modified: amazon/__pycache__/price_match.cpython-39.pyc

modified:   amazon/price_match.py
	modified:   assets/appearance-patent.js
	modified:   assets/delete-brand.js
	modified:   assets/patrol-delete.js
	modified:   assets/price-track.js
	modified:   assets/product-risk.js
	modified:   assets/query-asin.js
	modified:   assets/shop-match.js
	modified:   new_web_source/delete-brand.html
This commit is contained in:
铭坤
2026-04-30 21:57:37 +08:00
parent 8e60f50616
commit 4eec0dd5a4
10 changed files with 213 additions and 198 deletions

View File

@@ -150,7 +150,18 @@ def calculate_target_price(
# 分支 A第一名是 Amazon US 卖家 (特殊强敌优先)
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) # 实际第一名价格
if "Amazon" in shop_name_1:
return RepricingLogic.situation_4_encounter_amz_us_1st(my_price,price_1)
# 增补第6种情况如果是自己购物车 且 第一名是Amazon 且Amazon的价格高于自己的价格 按照这个 :如果低于自己的价格 就跳过,
if is_my_buybox:
if price_1 > my_price:
diff = price_1 - my_price
if diff <= 7 :
return None
else:
return price_1 - 5
else:
return None
else:
return RepricingLogic.situation_4_encounter_amz_us_1st(my_price,price_1)
# 分支 B不是 Amazon US且目前是自己的购物车
elif is_my_buybox:
@@ -360,10 +371,11 @@ class ChromeAmzone:
self.tab.wait.doc_loaded(timeout=5,raise_err=False)
# 3. 抓取数据
print("正在抓取商品数据...")
print("===================正在抓取商品数据...====================")
data = self._scrape_data()
data['timestamp'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(f"数据抓取完成: {json.dumps(data)}")
print("======================================================")
return data
except Exception as e:
@@ -658,161 +670,163 @@ class AmzonePriceMatch(AmamzonBase):
# for sku_ele in sku_ls[0:2]:
for sku_ele in sku_ls:
asin = sku_ele.ele(
'xpath:.//div[contains(@class,"JanusSplitBox-module__container")]//div[contains(@class,"JanusSplitBox-module__panel--") and contains(string(.),"ASIN")]/..//div[last()]',
timeout=3).text
print(f"{self.mark_name}】ASIN {asin} 找到....")
# if asin in already_asin:
# print(f"【{self.mark_name}】{asin} 已经处理过了,跳过")
# continue
if asin in skip_asin:
yield (asin, {
"statu": "跳过,需要跳过的ASIN"
})
continue
bottom_price_ele = sku_ele.eles('xpath:.//div[@data-test-id="LowestPrice"]/div[2]',timeout=5)
bottom_price = "" #初始化为空
if len(bottom_price_ele) > 0:
try:
bottom_price_text = bottom_price_ele[0].text
# print("最低价格->>",bottom_price_text)
bottom_price = f"{sum(split_currency_values(bottom_price_text))}"
except Exception as e:
print("最低价提取失败",e)
try:
# if asin in already_asin:
# print(f"【{self.mark_name}】{asin} 已经处理过了,跳过")
# continue
if asin in skip_asin:
yield (asin, {
"statu": "跳过,需要跳过的ASIN"
})
continue
bottom_price_ele = sku_ele.eles('xpath:.//div[@data-test-id="LowestPrice"]/div[2]',timeout=5)
bottom_price = "" #初始化为空
if len(bottom_price_ele) > 0:
try:
bottom_price_text = bottom_price_ele[0].text
# print("最低价格->>",bottom_price_text)
bottom_price = f"{sum(split_currency_values(bottom_price_text))}"
except Exception as e:
print("最低价提取失败",e)
current_price_ele = sku_ele.eles('xpath:.//b[text()="价格"]/../..//kat-input',timeout=5)
if len(current_price_ele) > 0:
current_price = current_price_ele[0].attr("value")
print("获取到当前价格为 ->",current_price)
# 如果紫鸟里当前价格低于最低价则删除,否则跳过
# if mode == "status" and miniprice_info.get(asin):
if miniprice_info.get(asin):
backend_price = float(miniprice_info.get(asin))
if float(current_price) <= backend_price:
yield (asin, {
"statu": "跳过(当前价格低于或等于最低价)",
"currentPrice": current_price,
"minimumPrice": bottom_price, # 最低价格
})
continue
current_price_ele = sku_ele.eles('xpath:.//b[text()="价格"]/../..//kat-input',timeout=5)
if len(current_price_ele) > 0:
current_price = current_price_ele[0].attr("value")
print("获取到当前价格为 ->",current_price)
# 如果紫鸟里当前价格低于最低价则删除,否则跳过
# if mode == "status" and miniprice_info.get(asin):
if miniprice_info.get(asin):
backend_price = float(miniprice_info.get(asin))
if float(current_price) <= backend_price:
yield (asin, {
"statu": "跳过(当前价格低于或等于最低价)",
"currentPrice": current_price,
"minimumPrice": bottom_price, # 最低价格
})
continue
else:
print(f"{self.mark_name} 没有获取到当前价格")
yield (asin, {
"statu": "失败(没有获取到当前的价格)"
})
continue
else:
print(f"{self.mark_name} 没有获取到当前价格")
yield (asin, {
"statu": "失败(没有获取到当前的价格)"
})
continue
self.clear_tab()
detail_url_ele = sku_ele.ele('xpath:.//div[contains(@class,"ProductDetails-module__titleContainer")]//a')
# detail_url_ele.click()
detail_url = detail_url_ele.attr("href")
print("详情链接",detail_url)
# time.sleep(1)
for _ in range(10):
try:
new_tab = self.browser.new_tab(url=detail_url)
print("获取新标签页成功",new_tab)
self.clear_tab()
detail_url_ele = sku_ele.ele('xpath:.//div[contains(@class,"ProductDetails-module__titleContainer")]//a')
# detail_url_ele.click()
detail_url = detail_url_ele.attr("href")
print("详情链接",detail_url)
# time.sleep(1)
for _ in range(10):
try:
new_tab = self.browser.new_tab(url=detail_url)
print("获取新标签页成功",new_tab)
time.sleep(1)
break
except Exception as e:
time.sleep(1)
pass
chrome = ChromeAmzone(tab=new_tab)
front_end_data = chrome.run(country=current_country)
chrome.close()
self.clear_tab()
print(self.mark_name,"亚马逊前台抓取到数据",front_end_data)
if front_end_data is None or len(front_end_data.get("top_sellers")) == 0:
yield (asin, {
"statu": "失败(第一名获取失败,请检查卖家精灵是否启用)",
"currentPrice": current_price,
})
continue
cart_seller = front_end_data.get("cart_seller")
if cart_seller == current_shop_name and len(front_end_data.get("top_sellers"))< 2:
yield (asin, {
"statu": "跳过(自己的购物车,只有第一名)",
"currentPrice": current_price,
})
continue
recommend_price_ele= sku_ele.eles('xpath:.//div[@data-test-id="FeaturedOfferPrice"]/div[2]',timeout=5)
if len(recommend_price_ele) > 0:
try:
price_text = recommend_price_ele[0].text
# print("推荐价格 ->>",price_text)
recommend_price,shipping_fee = split_currency_values(price_text)
except Exception as e:
print("推荐价格和运费提取失败 ->>",e)
recommend_price, shipping_fee = 0, 0
else:
print(f"{self.mark_name} 没有查找有推荐价格和运费")
recommend_price,shipping_fee = 0,0
adjust_prices = calculate_target_price(
front_end_data, float(current_price), current_shop_name,
recommend_price, shipping_fee
)
# adjust_prices = 236.56
print(asin,"-->>",f"【逻辑计算后的价格】",adjust_prices)
if adjust_prices is not None and adjust_prices != float(current_price):
#修改价格
print("准备填入的原始值:",adjust_prices)
adjust_prices = round(adjust_prices, 2)
print("保留两位小数后的::",adjust_prices)
self.tab.actions.click(current_price_ele[0])
time.sleep(1)
break
except Exception as e:
current_price_ele[0].input(f"{adjust_prices}", clear=True)
time.sleep(1)
pass
chrome = ChromeAmzone(tab=new_tab)
front_end_data = chrome.run(country=current_country)
chrome.close()
self.clear_tab()
print(self.mark_name,"亚马逊前台抓取到数据",front_end_data)
if front_end_data is None or len(front_end_data.get("top_sellers")) == 0:
yield (asin, {
"statu": "失败(第一名获取失败,请检查卖家精灵是否启用)",
"currentPrice": current_price,
})
# current_price_ele[0].sr('xpath:.//inpu[@part="input"]').input(f"{adjust_prices}",clear=True)
out_focus = sku_ele.ele('xpath:.//b[text()="价格"]/../..//kat-label',timeout=5)
out_focus.click()
time.sleep(1)
save_all_btn = self.tab.ele('xpath://kat-button[@label="保存所有"]', timeout=10)
save_all_btn.wait.displayed(timeout=10, raise_err=False)
save_all_btn.click()
save_all_btn.wait.deleted(timeout=10, raise_err=False)
recommendedPrice = recommend_price + shipping_fee
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) if len(front_end_data.get("top_sellers")) >= 2 else "" # 实际第一名价格
price_2 = float(front_end_data.get("top_sellers")[1].get("price")) if len(front_end_data.get("top_sellers")) >= 2 else "" # 实际第二名价格
cartShopName = front_end_data.get("cart_seller")
yield (asin,{
"statu" : "改价成功",
"currentPrice" : current_price,
"recommendedPrice" : f"{recommendedPrice}",
"minimumPrice" : f"{miniprice_info.get(asin)}" if miniprice_info.get(asin) else "",#bottom_price, #最低价格
"firstPlace": price_1,
"secondPlace": price_2,
"cartShopName" : cartShopName,
"shippingFee" : f"{shipping_fee}",
"priceChangePrice" : f"{adjust_prices}",
"priceChangeStatus" : "改价成功",
})
else:
recommendedPrice = recommend_price + shipping_fee
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) if len(
front_end_data.get("top_sellers")) >= 2 else "" # 实际第一名价格
price_2 = float(front_end_data.get("top_sellers")[1].get("price")) if len(
front_end_data.get("top_sellers")) >= 2 else "" # 实际第二名价格
cartShopName = front_end_data.get("cart_seller")
yield (asin, {
"statu": "跳过,无需改价",
"currentPrice": current_price,
"recommendedPrice": f"{recommendedPrice}",
# "minimumPrice": bottom_price, # 最低价格
"minimumPrice": f"{miniprice_info.get(asin)}" if miniprice_info.get(asin) else "",
"firstPlace": price_1,
"secondPlace": price_2,
"cartShopName": cartShopName,
"shippingFee": f"{shipping_fee}",
"priceChangeStatus": "跳过,无需改价",
"priceChangePrice": f"{adjust_prices}".replace("None",""),
})
except Exception as e:
print(f"{asin},操作出错,{e}")
continue
cart_seller = front_end_data.get("cart_seller")
if cart_seller == current_shop_name and len(front_end_data.get("top_sellers"))< 2:
yield (asin, {
"statu": "跳过(自己的购物车,只有第一名)",
"currentPrice": current_price,
})
continue
recommend_price_ele= sku_ele.eles('xpath:.//div[@data-test-id="FeaturedOfferPrice"]/div[2]',timeout=5)
if len(recommend_price_ele) > 0:
try:
price_text = recommend_price_ele[0].text
# print("推荐价格 ->>",price_text)
recommend_price,shipping_fee = split_currency_values(price_text)
except Exception as e:
print("推荐价格和运费提取失败 ->>",e)
recommend_price, shipping_fee = 0, 0
else:
print(f"{self.mark_name} 没有查找有推荐价格和运费")
recommend_price,shipping_fee = 0,0
adjust_prices = calculate_target_price(
front_end_data, float(current_price), current_shop_name,
recommend_price, shipping_fee
)
# adjust_prices = 236.56
print(asin,"-->>",f"【逻辑计算后的价格】",adjust_prices)
if adjust_prices is not None and adjust_prices != float(current_price):
#修改价格
print("准备填入的原始值:",adjust_prices)
adjust_prices = round(adjust_prices, 2)
print("保留两位小数后的::",adjust_prices)
self.tab.actions.click(current_price_ele[0])
time.sleep(1)
current_price_ele[0].input(f"{adjust_prices}", clear=True)
time.sleep(1)
# current_price_ele[0].sr('xpath:.//inpu[@part="input"]').input(f"{adjust_prices}",clear=True)
out_focus = sku_ele.ele('xpath:.//b[text()="价格"]/../..//kat-label',timeout=5)
out_focus.click()
time.sleep(1)
save_all_btn = self.tab.ele('xpath://kat-button[@label="保存所有"]', timeout=10)
save_all_btn.wait.displayed(timeout=10, raise_err=False)
save_all_btn.click()
save_all_btn.wait.deleted(timeout=10, raise_err=False)
recommendedPrice = recommend_price + shipping_fee
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) if len(front_end_data.get("top_sellers")) >= 2 else "" # 实际第一名价格
price_2 = float(front_end_data.get("top_sellers")[1].get("price")) if len(front_end_data.get("top_sellers")) >= 2 else "" # 实际第二名价格
cartShopName = front_end_data.get("cart_seller")
yield (asin,{
"statu" : "改价成功",
"currentPrice" : current_price,
"recommendedPrice" : f"{recommendedPrice}",
"minimumPrice" : f"{miniprice_info.get(asin)}" if miniprice_info.get(asin) else "",#bottom_price, #最低价格
"firstPlace": price_1,
"secondPlace": price_2,
"cartShopName" : cartShopName,
"shippingFee" : f"{shipping_fee}",
"priceChangePrice" : f"{adjust_prices}",
"priceChangeStatus" : "改价成功",
})
else:
recommendedPrice = recommend_price + shipping_fee
price_1 = float(front_end_data.get("top_sellers")[0].get("price")) if len(
front_end_data.get("top_sellers")) >= 2 else "" # 实际第一名价格
price_2 = float(front_end_data.get("top_sellers")[1].get("price")) if len(
front_end_data.get("top_sellers")) >= 2 else "" # 实际第二名价格
cartShopName = front_end_data.get("cart_seller")
yield (asin, {
"statu": "跳过,无需改价",
"currentPrice": current_price,
"recommendedPrice": f"{recommendedPrice}",
# "minimumPrice": bottom_price, # 最低价格
"minimumPrice": f"{miniprice_info.get(asin)}" if miniprice_info.get(asin) else "",
"firstPlace": price_1,
"secondPlace": price_2,
"cartShopName": cartShopName,
"shippingFee": f"{shipping_fee}",
"priceChangeStatus": "跳过,无需改价",
"priceChangePrice": f"{adjust_prices}".replace("None",""),
})
already_asin.add(asin)
# 判断是否存在需要翻页的情况
@@ -1417,49 +1431,49 @@ class PriceTask:
if __name__ == '__main__':
# 使用示例
# user_info = {
# "company": "尾号5578的公司115",
# "username": "自动化_Robot",
# "password": "#20zsg25"
# }
# shop_name = "刘建煌"
# country = "法国"
# kill_process('v6')
# driver = AmzonePriceMatch(user_info)
# browser = driver.open_shop(shop_name)
# sw_suc = driver.SwitchingCountries(country)
# driver.SwitchPage()
# risk_listing_filter = "Active"
# _shopMallName = "Jianhuang 888"
# ap_asin ="B0F25Y52PH"
# skip_asin = []
# for _ in range(3):
# try:
# sku_ls = driver.search(filter_type=risk_listing_filter)
# break
# except Exception as e:
# print(e)
# driver.tab.refresh()
# if len(sku_ls) > 0:
# print("有数据,开始操作")
# for asin, status in driver.run_page_action(
# current_shop_name=_shopMallName,
# appoint_asin=ap_asin,skip_asin=skip_asin,mode="asin"
# ):
# print(f"ASIN {asin} 的处理结果: {status}")
# print("已完成操作")
user_info = {
"company": "尾号5578的公司115",
"username": "自动化_Robot",
"password": "#20zsg25"
}
shop_name = "刘建煌"
country = "法国"
kill_process('v6')
driver = AmzonePriceMatch(user_info)
browser = driver.open_shop(shop_name)
sw_suc = driver.SwitchingCountries(country)
driver.SwitchPage()
risk_listing_filter = "Active"
_shopMallName = "Jianhuang 888"
ap_asin ="B0F25Y52PH"
skip_asin = []
for _ in range(3):
try:
sku_ls = driver.search(filter_type=risk_listing_filter)
break
except Exception as e:
print(e)
driver.tab.refresh()
if len(sku_ls) > 0:
print("有数据,开始操作")
for asin, status in driver.run_page_action(
current_shop_name=_shopMallName,
appoint_asin=ap_asin,skip_asin=skip_asin,mode="asin"
):
print(f"ASIN {asin} 的处理结果: {status}")
print("已完成操作")
front_end_data = {'top_sellers': [{'rank': 1, 'price': '52.51', 'stock': '100', 'shop_name': 'Amazon US'}, {'rank': 2, 'price': '62.58', 'stock': '30', 'shop_name': 'Amazon US'}], 'cart_seller': 'Jianhuang 888', 'timestamp': '2026-04-30 09:52:49'}
current_Price = 52.51
current_shop_name = "Jianhuang 888"
recommended_price = 52.51
recommended_shipping =0.0
res = calculate_target_price(
front_end_data, current_Price, current_shop_name,
recommended_price, recommended_shipping
)
print(res)
# front_end_data = {'top_sellers': [{'rank': 1, 'price': '52.51', 'stock': '100', 'shop_name': 'Amazon US'}, {'rank': 2, 'price': '62.58', 'stock': '30', 'shop_name': 'Amazon US'}], 'cart_seller': 'Jianhuang 888', 'timestamp': '2026-04-30 09:52:49'}
#
# current_Price = 52.51
# current_shop_name = "Jianhuang 888"
# recommended_price = 52.51
# recommended_shipping =0.0
# res = calculate_target_price(
# front_end_data, current_Price, current_shop_name,
# recommended_price, recommended_shipping
# )
# print(res)
# task_data = {'type': 'price-track-run', 'ts': 1777388166302, 'data': {'task_id': 4892, 'result_id': 6685, 'shop_name': '魏振峰', 'shop_id': '27543917795757', 'platform': '亚马逊', 'company_name': 'rongchuang123', 'shop_mall_name': 'WEIZHENFENG168', 'matched': True, 'match_status': 'MATCHED', 'match_message': None, 'success': False, 'error': None, 'output_filename': None, 'download_url': None, 'task_status': 'RUNNING', 'loop_run_id': 168, 'round_index': 1, 'country_codes': ['DE', 'UK', 'FR', 'IT', 'ES'], 'mode': 'asin', 'skip_asins': {}, 'skip_asins_by_country': {}, 'skip_asin_details_by_country': {}, 'minimum_price_by_country_and_asin': {'DE': {'B0CFY5M3XJ': '38', 'B0DSJGJBWV': '9'}, 'UK': {'B0G2LPSGP5': '30', 'B0G1LY2K8L': '10'}}, 'skip_asin_delete_policy': {'enabled': False, 'mode': 'NONE', 'deleteWhenPriceBelowMinimum': False, 'compareField': 'price', 'thresholdField': 'minimumPrice', 'target': 'skip_asin', 'source': 'frontend-price-track'}, 'delete_skip_asin_when_price_below_minimum': False, 'deleteSkipAsinWhenPriceBelowMinimum': False, 'asin_rows_by_country': {'DE': [{'shopMallName': '', 'asin': 'B0CFY5M3XJ', 'price': '', 'recommendedPrice': '', 'minimumPrice': '38', 'firstPlace': '', 'secondPlace': '', 'cartShopName': '', 'priceChangeStatus': '', 'modifyCount': '', 'status': ''}, {'shopMallName': '', 'asin': 'B0DSJGJBWV', 'price': '', 'recommendedPrice': '', 'minimumPrice': '9', 'firstPlace': '', 'secondPlace': '', 'cartShopName': '', 'priceChangeStatus': '', 'modifyCount': '', 'status': ''}], 'UK': [{'shopMallName': '', 'asin': 'B0G2LPSGP5', 'price': '', 'recommendedPrice': '', 'minimumPrice': '30', 'firstPlace': '', 'secondPlace': '', 'cartShopName': '', 'priceChangeStatus': '', 'modifyCount': '', 'status': ''}, {'shopMallName': '', 'asin': 'B0G1LY2K8L', 'price': '', 'recommendedPrice': '', 'minimumPrice': '10', 'firstPlace': '', 'secondPlace': '', 'cartShopName': '', 'priceChangeStatus': '', 'modifyCount': '', 'status': ''}]}, 'taskId': 4892, 'resultId': 6685, 'shopName': '魏振峰', 'shopId': '27543917795757', 'platformName': '亚马逊', 'companyName': 'rongchuang123', 'shopMallName': 'WEIZHENFENG168', 'matchStatus': 'MATCHED', 'matchMessage': None, 'outputFilename': None, 'downloadUrl': None, 'taskStatus': 'RUNNING', 'loopRunId': 168, 'roundIndex': 1}}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -7,8 +7,9 @@
<script type="module" crossorigin src="/assets/delete-brand.js"></script>
<link rel="modulepreload" crossorigin href="/assets/pywebview-C66x_2Dh.js">
<link rel="modulepreload" crossorigin href="/assets/brand-BZije8D7.js">
<link rel="modulepreload" crossorigin href="/assets/categorized-timers-JPA-olTr.js">
<link rel="stylesheet" crossorigin href="/assets/pywebview-Dp5dN8OO.css">
<link rel="stylesheet" crossorigin href="/assets/delete-brand-BP3XWKAC.css">
<link rel="stylesheet" crossorigin href="/assets/delete-brand-BfMLVSQU.css">
</head>
<body>
<div id="app"></div>