Python – Scraping a JSON response with Scrapy

import scrapy
import json


class FlashsaleSpider(scrapy.Spider):
    name = 'flashsale'
    allowed_domains = ['indonesia-covid-19.mathdro.id']
    start_urls = ['https://indonesia-covid-19.mathdro.id/api/provinsi']


    def parse(self, response):
        resp = json.loads(response.body)
        rows = resp.get('data')
        for row in rows:
            yield {
                'provinsi': row.get('provinsi'),
                'positif': row.get('kasusPosi'),
                'sembuh': row.get('kasusSemb'),
                'menginggal': row.get('kasusMeni')
            }

Leave a Reply

Your email address will not be published. Required fields are marked *