提交货源图片和相似ASIN优化
This commit is contained in:
@@ -79,7 +79,8 @@ class ChromeAmzone(ChromeAmzoneBase):
|
||||
except Exception as e:
|
||||
error_msg = f"运行出错: {traceback.format_exc()}"
|
||||
self.log(error_msg)
|
||||
show_notification(f"采集失败: {str(e)}", "error")
|
||||
# show_notification(f"采集失败: {str(e)}", "error")
|
||||
raise RuntimeError(error_msg)
|
||||
return {}
|
||||
|
||||
def _scrape_data(self):
|
||||
@@ -100,8 +101,27 @@ class ChromeAmzone(ChromeAmzoneBase):
|
||||
title_ele = self.tab.ele('xpath://h1[@id="title"]',timeout=30)
|
||||
title = title_ele.text
|
||||
data["title"] = title
|
||||
sku_ele_ls = self.tab.eles('xpath://ul[@class="a-unordered-list a-vertical a-spacing-mini"]', timeout=20)
|
||||
if len(sku_ele_ls) > 0:
|
||||
data["title"] += sku_ele_ls[0].text
|
||||
imge_ele = self.tab.ele('xpath://div[@id="imgTagWrapperId"]//img',timeout=20)
|
||||
image_url = imge_ele.attr("src")
|
||||
|
||||
image_url = ""
|
||||
data_a_dynamic_image = imge_ele.attr("data-a-dynamic-image")
|
||||
if data_a_dynamic_image:
|
||||
dynamic_image_json = json.loads(data_a_dynamic_image)
|
||||
self.log(f"图片信息:{dynamic_image_json}")
|
||||
max_area = 0
|
||||
|
||||
for url, (width, height) in dynamic_image_json.items():
|
||||
area = width * height
|
||||
if area > max_area:
|
||||
max_area = area
|
||||
image_url = url
|
||||
|
||||
if not image_url:
|
||||
image_url = imge_ele.attr("src")
|
||||
|
||||
data["image_url"] = image_url
|
||||
return data
|
||||
|
||||
@@ -263,7 +283,7 @@ class SpiderTask(TaskBase):
|
||||
result.append(res)
|
||||
print("================")
|
||||
is_done = gp_index == len(groups)-1
|
||||
if len(result) > 20 or is_done:
|
||||
if len(result) > 10 or is_done:
|
||||
self.post_result(task_id=task_id,chunkIndex=gp_index+1,chunkTotal=len(groups),
|
||||
asin=asin,item_data=result,is_done=is_done)
|
||||
result = []
|
||||
|
||||
Reference in New Issue
Block a user