im trying to scrape the info from www.kimovil.com and i have one issue with the prices.
i want to scrapy only this price --> field to read
but when i inspect that i see what is a list with diferent country prices an by default the first on read is the germany price so i got 989€ instead 1090
how can i scrapy the spanish price???
CodePudding user response:
Why don't you try using requests
by accessing the kimovil API instead of scrapy
? Here's something to start with:
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)
The endpoint you're looking for has the following structure:
https://www.kimovil.com/_json/<name-of-the-phone>_prices_deals.json
I tested it with a couple of phone models and it works just fine. You just have to update the PHONE_MODEL
to match the name of the phone as it shows on their page.
This is how the response would look like:
{
"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"
}
CodePudding user response:
Espero que sea para un proyecto personal Roberto