如何用scrapy抓取所有的价格数据

bqjvbblv  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(141)

我试图刮的信息从www.kimovil.com和我有一个问题的价格。
我只想拼这个价格--〉field to read
但是当我检查的时候,我看到的是一个不同国家的价格列表,默认情况下,第一个读到的是德国的价格,所以我得到了989欧元而不是1090欧元。
Inspector view
我怎么能把西班牙的价格降低呢???

dfty9e19

dfty9e191#

为什么不尝试通过访问kimovil API而不是scrapy来使用requests呢?

import requests
import re

PHONE_MODEL = 'realme GT 2 Pro'

response = requests.get('https://www.kimovil.com/_json/{}_prices_deals.json'.format(re.sub("\s", "-", PHONE_MODEL.lower())))

print(response.text)

您要查找的终结点具有以下结构:

https://www.kimovil.com/_json/<name-of-the-phone>_prices_deals.json

我用几个手机型号测试了它,它运行得很好。你只需要更新PHONE_MODEL,以匹配手机的名称,因为它显示在他们的页面上。
响应如下所示:

{
   "prices":[
      {
         "device_id":10999,
         "id":2193117,
         "originalPrice":"628.17",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/XFF8R3",
         "hash":"XFF8R3",
         "provider":{
            "id":522,
            "provider_group_id":525,
            "countryDeliveryTo":{
               "countryCode":"XX"
            },
            "destinationCountries":[
               "US",
               "RU",
               "BR",
               "CO",
               "PE",
               "MX"
            ],
            "country_sale_restriction":[
               "BR",
               "MX",
               "RU",
               "PE"
            ],
            "warehouse_country_code":"CN"
         },
         "eurPrice":"628.17",
         "gbpPrice":"525.89",
         "usdPrice":"644.81",
         "rubPrice":"41659.90",
         "inrPrice":"50897.95",
         "plnPrice":"2962.73",
         "brlPrice":"3342.91",
         "mxnPrice":"13142.91"
      },
      {
         "device_id":10999,
         "id":2076448,
         "originalPrice":"638.40",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/273TTX",
         "hash":"273TTX",
         "provider":{
            "id":684,
            "provider_group_id":536,
            "countryDeliveryTo":{
               "countryCode":"XX"
            },
            "destinationCountries":[
               "XX"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"CN"
         },
         "eurPrice":"638.40",
         "gbpPrice":"533.62",
         "usdPrice":"649.06",
         "rubPrice":"39420.09",
         "inrPrice":"51005.78",
         "plnPrice":"3014.28",
         "brlPrice":"3425.62",
         "mxnPrice":"13485.12"
      },
      {
         "device_id":10999,
         "id":2040143,
         "originalPrice":"683.00",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/6R5HNG",
         "hash":"6R5HNG",
         "provider":{
            "id":528,
            "provider_group_id":394,
            "countryDeliveryTo":{
               "countryCode":"XX"
            },
            "destinationCountries":[
               "XX"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"CN"
         },
         "eurPrice":"683.00",
         "gbpPrice":"570.90",
         "usdPrice":"694.41",
         "rubPrice":"42174.06",
         "inrPrice":"54569.15",
         "plnPrice":"3224.87",
         "brlPrice":"3664.94",
         "mxnPrice":"14427.22"
      },
      {
         "device_id":10999,
         "id":2077019,
         "originalPrice":"722.69",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/B4Z2BF",
         "hash":"B4Z2BF",
         "provider":{
            "id":688,
            "provider_group_id":11,
            "countryDeliveryTo":{
               "countryCode":"XX"
            },
            "destinationCountries":[
               "US",
               "RU",
               "BR",
               "CO",
               "PE",
               "MX"
            ],
            "country_sale_restriction":[
               "BR",
               "MX",
               "RU",
               "PE"
            ],
            "warehouse_country_code":"CN"
         },
         "eurPrice":"722.69",
         "gbpPrice":"605.02",
         "usdPrice":"741.83",
         "rubPrice":"47928.41",
         "inrPrice":"58556.51",
         "plnPrice":"3408.52",
         "brlPrice":"3845.92",
         "mxnPrice":"15120.50"
      },
      {
         "device_id":10999,
         "id":2077027,
         "originalPrice":"722.69",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/3N2PL8",
         "hash":"3N2PL8",
         "provider":{
            "id":646,
            "provider_group_id":11,
            "countryDeliveryTo":{
               "countryCode":"XX"
            },
            "destinationCountries":[
               "US",
               "RU",
               "BR",
               "CO",
               "PE",
               "MX"
            ],
            "country_sale_restriction":[
               "BR",
               "MX",
               "RU",
               "PE"
            ],
            "warehouse_country_code":"CN"
         },
         "eurPrice":"722.69",
         "gbpPrice":"605.02",
         "usdPrice":"741.83",
         "rubPrice":"47928.41",
         "inrPrice":"58556.51",
         "plnPrice":"3408.52",
         "brlPrice":"3845.92",
         "mxnPrice":"15120.50"
      },
      {
         "device_id":10999,
         "id":2035914,
         "originalPrice":"782.99",
         "originalCurrency":"USD",
         "shortHash":"https:\/\/www.kimovil.com\/to\/PSNG1S",
         "hash":"PSNG1S",
         "provider":{
            "id":343,
            "provider_group_id":229,
            "countryDeliveryTo":{
               "countryCode":"XX"
            },
            "destinationCountries":[
               "XX"
            ],
            "country_sale_restriction":[
               "RU",
               "BR",
               "MX"
            ],
            "warehouse_country_code":"CN"
         },
         "eurPrice":"770.13",
         "gbpPrice":"643.73",
         "usdPrice":"782.99",
         "rubPrice":"47554.12",
         "inrPrice":"61530.42",
         "plnPrice":"3636.26",
         "brlPrice":"4132.47",
         "mxnPrice":"16267.67"
      },
      {
         "device_id":10999,
         "id":2527843,
         "originalPrice":"815.00",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/4C1JF3",
         "hash":"4C1JF3",
         "provider":{
            "id":846,
            "provider_group_id":206,
            "countryDeliveryTo":{
               "countryCode":"DE"
            },
            "destinationCountries":[
               "DE"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"GB"
         },
         "eurPrice":"815.00",
         "gbpPrice":"681.23",
         "usdPrice":"828.61",
         "rubPrice":"50324.83",
         "inrPrice":"65115.46",
         "plnPrice":"3848.12",
         "brlPrice":"4373.24",
         "mxnPrice":"17215.50"
      },
      {
         "device_id":10999,
         "id":2527875,
         "originalPrice":"815.00",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/MR65RB",
         "hash":"MR65RB",
         "provider":{
            "id":844,
            "provider_group_id":206,
            "countryDeliveryTo":{
               "countryCode":"ES"
            },
            "destinationCountries":[
               "ES"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"GB"
         },
         "eurPrice":"815.00",
         "gbpPrice":"681.23",
         "usdPrice":"828.61",
         "rubPrice":"50324.83",
         "inrPrice":"65115.46",
         "plnPrice":"3848.12",
         "brlPrice":"4373.24",
         "mxnPrice":"17215.50"
      },
      {
         "device_id":10999,
         "id":2527951,
         "originalPrice":"815.00",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/S8GBMT",
         "hash":"S8GBMT",
         "provider":{
            "id":847,
            "provider_group_id":206,
            "countryDeliveryTo":{
               "countryCode":"FR"
            },
            "destinationCountries":[
               "FR"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"GB"
         },
         "eurPrice":"815.00",
         "gbpPrice":"681.23",
         "usdPrice":"828.61",
         "rubPrice":"50324.83",
         "inrPrice":"65115.46",
         "plnPrice":"3848.12",
         "brlPrice":"4373.24",
         "mxnPrice":"17215.50"
      },
      {
         "device_id":10999,
         "id":2528034,
         "originalPrice":"815.00",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/H261CY",
         "hash":"H261CY",
         "provider":{
            "id":843,
            "provider_group_id":206,
            "countryDeliveryTo":{
               "countryCode":"GR"
            },
            "destinationCountries":[
               "GR"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"GB"
         },
         "eurPrice":"815.00",
         "gbpPrice":"681.23",
         "usdPrice":"828.61",
         "rubPrice":"50324.83",
         "inrPrice":"65115.46",
         "plnPrice":"3848.12",
         "brlPrice":"4373.24",
         "mxnPrice":"17215.50"
      },
      {
         "device_id":10999,
         "id":2528111,
         "originalPrice":"815.00",
         "originalCurrency":"EUR",
         "shortHash":"https:\/\/www.kimovil.com\/to\/M294BB",
         "hash":"M294BB",
         "provider":{
            "id":1096,
            "provider_group_id":206,
            "countryDeliveryTo":{
               "countryCode":"IT"
            },
            "destinationCountries":[
               "IT"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"GB"
         },
         "eurPrice":"815.00",
         "gbpPrice":"681.23",
         "usdPrice":"828.61",
         "rubPrice":"50324.83",
         "inrPrice":"65115.46",
         "plnPrice":"3848.12",
         "brlPrice":"4373.24",
         "mxnPrice":"17215.50"
      },
      {
         "device_id":10999,
         "id":2528217,
         "originalPrice":"684.78",
         "originalCurrency":"GBP",
         "shortHash":"https:\/\/www.kimovil.com\/to\/WSBL8Z",
         "hash":"WSBL8Z",
         "provider":{
            "id":845,
            "provider_group_id":206,
            "countryDeliveryTo":{
               "countryCode":"GB"
            },
            "destinationCountries":[
               "GB"
            ],
            "country_sale_restriction":[

            ],
            "warehouse_country_code":"GB"
         },
         "eurPrice":"819.24",
         "gbpPrice":"684.78",
         "usdPrice":"832.92",
         "rubPrice":"50586.78",
         "inrPrice":"65454.40",
         "plnPrice":"3868.15",
         "brlPrice":"4396.00",
         "mxnPrice":"17305.11"
      }
   ],
   "deals":[

   ],
   "active_campaign":{
      "id":5,
      "slug":"dailydeals",
      "campaign_translations":{
         "en":{
            "url":"https:\/\/www.kimovil.com\/en\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         },
         "es":{
            "url":"https:\/\/www.kimovil.com\/es\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini-image_es.jpg"
         },
         "ru":{
            "url":"https:\/\/www.kimovil.com\/ru\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         },
         "de":{
            "url":"https:\/\/www.kimovil.com\/de\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         },
         "fr":{
            "url":"https:\/\/www.kimovil.com\/fr\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         },
         "it":{
            "url":"https:\/\/www.kimovil.com\/it\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         },
         "el":{
            "url":"https:\/\/www.kimovil.com\/el\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         },
         "pt":{
            "url":"https:\/\/www.kimovil.com\/pt\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         },
         "pl":{
            "url":"https:\/\/www.kimovil.com\/pl\/special\/dailydeals",
            "image":"\/\/d2giyh01gjb6fi.cloudfront.net\/images\/special_campaign\/daily_deals\/mini_image_en.jpg"
         }
      }
   },
   "timestamp":"1659515690",
   "datetime":"Wed, 03 Aug 2022 10:34:50 +0200"
}

相关问题