Oma_Inge
Oma_Inge

Reputation: 23

Scrape values from json python requests

So I am building a scraper for sizes on a site and I am confused how to extract the "EUR" and "pieces" from this JSON. I want to print all sizes like "EU 41 = Pieces 6".

Here is the output of the JSON:

{
  'translations': {
    'en': {
      'lang': 'en',
      'title': 'Nike Dunk Low Retro Premium',
      'subtitle': 'Black / Pure Platinum-Anthracite',
      'slug': 'nike-dunk-low-retro-premium',
      'description': 'DH7913-001'
    }
  },
  'id': 'vpEW0nkBHBhvh4GFDXSb',
  'prices': {
    'EUR': {
      'currency': 'EUR',
      'value': 119
    }
  },
  'sizeSets': {
    'Men': {
      'name': 'Men',
      'sizes': [{
        'id': '685d200c-c470-11eb-b5ee-a66da43170c1',
        'us': '8',
        'eur': '41',
        'uk': '7',
        'cm': '26',
        'ean': '194955875308',
        'pieces': 6
      }, {
        'id': '685d21c4-c470-11eb-9f9f-a66da43170c1',
        'us': '8.5',
        'eur': '42',
        'uk': '7.5',
        'cm': '26.5',
        'ean': '194955875315',
        'pieces': 18
      }, {
        'id': '685d232c-c470-11eb-8bda-a66da43170c1',
        'us': '9',
        'eur': '42.5',
        'uk': '8',
        'cm': '27',
        'ean': '194955875322',
        'pieces': 10
      }, {
        'id': '685d248a-c470-11eb-bf78-a66da43170c1',
        'us': '9.5',
        'eur': '43',
        'uk': '8.5',
        'cm': '27.5',
        'ean': '194955875339',
        'pieces': 17
      }, {
        'id': '685d25de-c470-11eb-8741-a66da43170c1',
        'us': '10',
        'eur': '44',
        'uk': '9',
        'cm': '28',
        'ean': '194955875346',
        'pieces': 15
      }, {
        'id': '685d2732-c470-11eb-bfb5-a66da43170c1',
        'us': '10.5',
        'eur': '44.5',
        'uk': '9.5',
        'cm': '28.5',
        'ean': '194955875353',
        'pieces': 5
      }, {
        'id': '685d2886-c470-11eb-ac68-a66da43170c1',
        'us': '11',
        'eur': '45',
        'uk': '10',
        'cm': '29',
        'ean': '194955875360',
        'pieces': 1
      }, {
        'id': '685d29e4-c470-11eb-8578-a66da43170c1',
        'us': '11.5',
        'eur': '45.5',
        'uk': '10.5',
        'cm': '29.5',
        'ean': '194955875377',
        'pieces': 2
      }, {
        'id': '685d2b38-c470-11eb-a729-a66da43170c1',
        'us': '12',
        'eur': '46',
        'uk': '11',
        'cm': '30',
        'ean': '194955875384',
        'pieces': 3
      }]
    },
    'Unisex': {
      'name': 'Unisex',
      'sizes': []
    },
    'Women': {
      'name': 'Women',
      'sizes': []
    },
    'Kids': {
      'name': 'Kids',
      'sizes': []
    }
  },
  'images': ['0/08/083/0837c383a3212d52f2e4455e0d876f47.jpeg', 'c/ca/ca0/ca01c2ca1dfb35013a06723b60c062cc.jpeg', '8/8e/8e9/8e9d04f6d1e8712da6d85c3db98ff989.jpeg', '3/37/376/3769e3f56186e46b91c725d09dff3252.jpeg', 'a/aa/aa5/aa5a8934a05be2badfe9cff5e07f122c.jpeg', '7/7b/7b0/7b088912b94bb0b2e41d527d573d568d.jpeg', 'b/b8/b8b/b8b214b6e1a33d56880e412b7ef8fe01.jpeg', '5/56/562/562809e497cc98b69cf8789e3238e482.jpeg'],
  'imagesPortrait': ['a/ab/abc/abc1eac4bcdf74bd899f8e2f7827f30c.jpeg'],
  'createdAt': '2021-06-03T13:34:22+00:00',
  'publishAt': '2021-06-10T10:00:00+00:00',
  'openRegistrationAt': '2021-06-10T10:00:00+00:00',
  'closeRegistrationAt': '2021-06-18T23:00:00+00:00',
  'finished': True,
  'headliner': False,
  'code': 'DH7913-001',
  'footshopLink': 'https://www.footshop.eu/en/723-limited-edition/orderby-activated_at/orderway-desc',
  'soldout': False,
  'deleted': False,
  'limitedShipping': True,
  'delayedExport': False,
  'productIdentifier': '115147',
  'status': 'Closed',
  'resultAt': '2021-06-19T03:00:00+00:00'
}
from os import error
import requests
from bs4 import BeautifulSoup
from discord_webhook import DiscordWebhook,DiscordEmbed
import time
import json


URL= "https://releases.footshop.com/api/raffles/vpEW0nkBHBhvh4GFDXSb"


headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36"}

page = requests.get(URL,headers=headers)

soup = BeautifulSoup(page.content, 'html.parser')


site_info= page.json()
print(site_info)

Upvotes: 0

Views: 71

Answers (1)

Cbdt
Cbdt

Reputation: 11

For the Json, I would recommend you first put it in a Json viewer/reader you can find online to see how is the data is more clearly and where is the information you want to get.

Here something like that should get you the information you want :

for s in site_info['sizeSets']['Men']['sizes']:
    print(s['eur']+' '+ str(s['pieces']))

Upvotes: 1

Related Questions