用Python获取中国大陆,香港,日本和美国苹果官网iphone价格

直接贴出来代码吧,比较简单
获取的都是无锁版本价格,美国官网的iphoneX无锁价格还没出,先略过。
另外都按当前汇率换算成了RMB价格。

#coding=utf-8
import urllib2
import json

url_japan_iphone7_32 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNCE2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphone7_128 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNCK2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphone7plus_32 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNRA2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphone7plus_128 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MN6G2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphone8_64 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ7A2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphone8_256 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ862J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphone8plus_64 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ9M2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphone8plus_256 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ9Q2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphonex_64 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_x&step=select&product=MQAY2J%2FA&carrierPolicyType=UNLOCKED'
url_japan_iphonex_256 = 'https://www.apple.com/jp/shop/updateSummary?node=home/shop_iphone/family/iphone_x&step=select&product=MQC22J%2FA&carrierPolicyType=UNLOCKED'

url_hongkong_iphone7_32 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MN8H2ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphone7_128 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MN8M2ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphone7plus_32 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNQJ2ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphone7plus_128 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MN492ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphone8_64 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ6M2ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphone8_256 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ7H2ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphone8plus_64 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ8F2ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphone8plus_256 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ8J2ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphonex_64 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_x&step=select&product=MQA62ZP%2FA&carrierPolicyType=UNLOCKED'
url_hongkong_iphonex_256 = 'https://www.apple.com/hk-zh/shop/updateSummary?node=home/shop_iphone/family/iphone_x&step=select&product=MQA92ZP%2FA&carrierPolicyType=UNLOCKED'

url_us_iphone7_32 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MN8H2LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'
url_us_iphone7_128 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MN8M2LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'
url_us_iphone7plus_32 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNQJ2LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'
url_us_iphone7plus_128 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MN492LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'
url_us_iphone8_64 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ6M2LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'
url_us_iphone8_256 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ7H2LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'
url_us_iphone8plus_64 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ8F2LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'
url_us_iphone8plus_256 = 'https://www.apple.com/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ8J2LL%2FA&cppart=UNLOCKED%2FUS&carrierPolicyType=UNLOCKED'

url_china_iphone7_32 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNGR2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphone7_128 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNGY2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphone7plus_32 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNRK2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphone7plus_128 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_7&step=select&product=MNFQ2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphone8_64 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ6M2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphone8_256 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ7H2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphone8plus_64 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ8F2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphone8plus_256 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_8&step=select&product=MQ8J2CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphonex_64 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_x&step=select&product=MQA62CH%2FA&carrierPolicyType=UNLOCKED'
url_china_iphonex_256 = 'https://www.apple.com/cn/shop/updateSummary?node=home/shop_iphone/family/iphone_x&step=select&product=MQA92CH%2FA&carrierPolicyType=UNLOCKED'

iphone_dic = {
"Japan\t\tiphone7\t\t32G": url_japan_iphone7_32, "Japan\t\tiphone7\t\t128G": url_japan_iphone7_128, "Japan\t\tiphone7plus\t32G": url_japan_iphone7plus_32, "Japan\t\tiphone7plus\t128G": url_japan_iphone7plus_128,
"Japan\t\tiphone8\t\t64G": url_japan_iphone8_64, "Japan\t\tiphone8\t\t256G": url_japan_iphone8_256, "Japan\t\tiphone8plus\t64G": url_japan_iphone8plus_64, "Japan\t\tiphone8plus\t256G": url_japan_iphone8plus_256,
"Japan\t\tiphoneX\t\t64G": url_japan_iphonex_64, "Japan\t\tiphoneX\t\t256G": url_japan_iphonex_256,
"HongKong\tiphone7\t\t32G": url_hongkong_iphone7_32, "HongKong\tiphone7\t\t128G": url_hongkong_iphone7_128, "HongKong\tiphone7plus\t32G": url_hongkong_iphone7plus_32, "HongKong\tiphone7plus\t128G": url_hongkong_iphone7plus_128,
"HongKong\tiphone8\t\t64G": url_hongkong_iphone8_64, "HongKong\tiphone8\t\t256G": url_hongkong_iphone8_256, "HongKong\tiphone8plus\t64G": url_hongkong_iphone8plus_64, "HongKong\tiphone8plus\t256G": url_hongkong_iphone8plus_256,
"HongKong\tiphoneX\t\t64G": url_hongkong_iphonex_64, "HongKong\tiphoneX\t\t256G": url_hongkong_iphonex_256,
"US\t\tiphone7\t\t32G": url_us_iphone7_32, "US\t\tiphone7\t\t128G": url_us_iphone7_128, "US\t\tiphone7plus\t32G": url_us_iphone7plus_32, "US\t\tiphone7plus\t128G": url_us_iphone7plus_128,
"US\t\tiphone8\t\t64G": url_us_iphone8_64, "US\t\tiphone8\t\t256G": url_us_iphone8_256, "US\t\tiphone8plus\t64G": url_us_iphone8plus_64, 'US\t\tiphone8plus\t256G': url_us_iphone8plus_256,
"China\t\tiphone7\t\t32G": url_china_iphone7_32, "China\t\tiphone7\t\t128G": url_china_iphone7_128, "China\t\tiphone7plus\t32G": url_china_iphone7plus_32, "China\t\tiphone7plus\t128G": url_china_iphone7plus_128,
"China\t\tiphone8\t\t64G": url_china_iphone8_64, "China\t\tiphone8\t\t256G": url_china_iphone8_256, "China\t\tiphone8plus\t64G": url_china_iphone8plus_64, "China\t\tiphone8plus\t256G": url_china_iphone8plus_256,
"China\t\tiphoneX\t\t64G": url_china_iphonex_64, "China\t\tiphoneX\t\t256G": url_china_iphonex_256}

def get_price():
    keys = iphone_dic.keys()
    l = sorted(keys)
    for des in l:
        url = iphone_dic[des]
        response = urllib2.urlopen(url)
        html = response.read()
        parsed_json = json.loads(html)
        seo_price = parsed_json['body']['response']['summarySection']['summary']['seoPrice']
        float_price = float(seo_price)
        if des.startswith('Japan'):
            float_price = float_price * 0.05926
        elif des.startswith('HongKong'):
            float_price = float_price * 0.8381
        elif des.startswith('US'):
            float_price = float_price * 6.5481
        print des + "\t" + u'¥' + str(float_price)

if __name__ == '__main__':
    get_price()
    print u'---END---'
    raw_input()

打印出来的数据为:

China           iphone7         128G    ¥5388.0
China           iphone7         32G     ¥4588.0
China           iphone7plus     128G    ¥6388.0
China           iphone7plus     32G     ¥5588.0
China           iphone8         256G    ¥7188.0
China           iphone8         64G     ¥5888.0
China           iphone8plus     256G    ¥7988.0
China           iphone8plus     64G     ¥6688.0
China           iphoneX         256G    ¥9688.0
China           iphoneX         64G     ¥8388.0
HongKong        iphone7         128G    ¥4683.3028
HongKong        iphone7         32G     ¥3929.0128
HongKong        iphone7plus     128G    ¥5605.2128
HongKong        iphone7plus     32G     ¥4850.9228
HongKong        iphone8         256G    ¥6108.0728
HongKong        iphone8         64G     ¥5018.5428
HongKong        iphone8plus     256G    ¥6862.3628
HongKong        iphone8plus     64G     ¥5772.8328
HongKong        iphoneX         256G    ¥8287.1328
HongKong        iphoneX         64G     ¥7197.6028
Japan           iphone7         128G    ¥4314.128
Japan           iphone7         32G     ¥3662.268
Japan           iphone7plus     128G    ¥5084.508
Japan           iphone7plus     32G     ¥4432.648
Japan           iphone8         256G    ¥5677.108
Japan           iphone8         64G     ¥4669.688
Japan           iphone8plus     256G    ¥6328.968
Japan           iphone8plus     64G     ¥5321.548
Japan           iphoneX         256G    ¥7691.948
Japan           iphoneX         64G     ¥6684.528
US              iphone7         128G    ¥4249.7169
US              iphone7         32G     ¥3594.9069
US              iphone7plus     128G    ¥5035.4889
US              iphone7plus     32G     ¥4380.6789
US              iphone8         256G    ¥5559.3369
US              iphone8         64G     ¥4577.1219
US              iphone8plus     256G    ¥6214.1469
US              iphone8plus     64G     ¥5231.9319
---END---

数据可供参考,如有错误欢迎指出。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 相关概念 面向对象的三个特征 封装,继承,多态.这个应该是人人皆知.有时候也会加上抽象. 多态的好处 允许不同类对...
    东经315度阅读 6,223评论 0 8
  • 前几天,有朋友去面试之前问我关于后端架构相关的问题,但奈于我去年更多的工作是在移动SDK开发上,对此有所遗忘,实属...
    涅槃1992阅读 10,779评论 8 76
  • 这次作业要求如下: 我选择了关于习惯的话题,这是我最近比较关注的话题。我选择的学习内容是拆书学院梦想赋能班水菱姑娘...
    毛美君阅读 3,188评论 7 9
  • url Nodejs的url模块只要提供一些实用函数,用于URL的处理和解析。在Nodejs中可以直接引用url模...
    漫漫前端阅读 5,572评论 0 1
  • 时光荏苒,四年岁月,千个日夜,弹指间就到了大四临近毕业了,回忆起这些大学时光里,多少都有一点遗憾和得失。有一次在跟...
    BeingBetter阅读 5,381评论 0 1