• python 获取lazada菲律宾站地址库


    import urllib3
    import requests
    import ast
    import time
    
    # 因为lazada返回的数据是json类型,通过解码成字符串类型,为了方便数据操作,使用字符串截取的方法将字符串格式化为包含字典的list
    
    def geshihua(s):
        m = s.index('[')
        n = s.index(']')
        s = s[m:n + 1]
        return ast.literal_eval(s)
    
        province_list = ast.literal_eval(province)
    
    # 通过国家代码获取省的名称及ID,返回包含字典的list
    def sheng(guo):
        requests.packages.urllib3.disable_warnings()
        http = urllib3.PoolManager()
        url = "https://member.lazada.com.ph//locationtree/api/getSubAddressList?countryCode=" + guo
        res = http.request('GET', url)
        province = res.data.decode()
        province_list = geshihua(province)
        sheng = []
        for p in province_list:
            sheng.append({'id':p['id'],'name':p['displayName']})
        return sheng
    
    
    # 通过国家代码及省ID或市ID获取市或者县的信息,返货包含字典的list
    def shixian(guo,sheng):
        requests.packages.urllib3.disable_warnings()
        http = urllib3.PoolManager()
        url = "https://member.lazada.com.ph//locationtree/api/getSubAddressList?countryCode=" + guo +"&addressId="+ sheng
        res = http.request('GET', url)
        province = res.data.decode()
        province_list = geshihua(province)
        shixian = []
        for p in province_list:
            shixian.append({'id':p['id'],'name':p['displayName']})
        return shixian
    
    
    # 只需要提供国家代码,即可遍历lazada该站的所有地名及编码
    def main():
    
        f = open('address.txt','a')
    
        g = "PH"
        s = sheng(g)
        for s1 in s:
            shi = shixian(g,s1['id'])
            for s2 in shi:
                xian = shixian(g,s2['id'])
                for x in xian:
                    f.write(s1['name']+','+s2['name']+','+x['name'])
                    f.write('
    ')
            time.sleep(1)
    
    
    
    if __name__=="__main__":
        main()
  • 相关阅读:
    ffmpeg mp4 视频输出为 aac 的命令
    git操作远程分支
    Linux (openSUSE 15.3 ) server ssh 可以使用,sftp无法使用
    小小思考题
    Linux 命令介绍
    2021 年 如何使用VMware 安装 ubuntu 7.04 虚拟机, 配置 apt 源
    Linux 下 命令行 使用浏览器
    oracle.cmd
    Sqlcmd
    vue eslint 配置使用
  • 原文地址:https://www.cnblogs.com/yyxianren/p/10694567.html
Copyright © 2020-2023  润新知