python脚本结合计算引擎快速获取亚马逊的父ASIN并保存到数据库

按照亚马逊的规则,一个ASIN只能有一个父ASIN,在某些情况下不得分析asin的所属变体父asin是否同一个。

Python代码。

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import op_data_web_hook as webhook
 
table_id_dp = "xxxx"
 
def get_parent_asin_by_page_source(res):
    if res is None:
        return ""
    try:
        res = str(res)
        parent_value = ""
        if res.__contains__("parentAsin="):
            parent_value = res.split("parentAsin=")[1].split("&")[0]
        elif res.__contains__(',"parentAsin":"'):
            parent_value = res.split(',"parentAsin":"')[1].split('",')[0]
        if parent_value is None or parent_value == "":
            return ""
        return parent_value
    except:
        return ""
 
def auto_get_and_save_parent_asin_by_page_source_and_asin(res, asin):
    parent_asin = get_parent_asin_by_page_source(res)
    if parent_asin != "":
        sql = "update table_id set update_time=now(),parent_asin='" + str(parent_asin) + "' where asin='" + str(asin) + "'"
        print("-- auto_get_and_save_parent_asin_by_page_source_and_asin --")
        print(sql)
        webhook.modify_by_sql_and_table_id(sql, table_id_dp)
        return 1
    return 0

 

 done

 

posted @   liskov_design  阅读(28)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示