python脚本结合计算引擎快速获取亚马逊的父ASIN并保存到数据库
按照亚马逊的规则,一个ASIN只能有一个父ASIN,在某些情况下不得分析asin的所属变体父asin是否同一个。
Python代码。
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