用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---

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

你可能感兴趣的:(用Python获取中国大陆,香港,日本和美国苹果官网iphone价格)