data scraping - field value - issue

Viewed 78

I like to obtain actual informaction about the numbers of infected from this website: https://www.gov.pl/web/koronawirus/wykaz-zarazen-koronawirusem-sars-cov-2

my code looks like:

import requests
from bs4 import BeautifulSoup
adresURL = 'https://www.gov.pl/web/koronawirus/wykaz-zarazen-koronawirusem-sars-cov-2'
res = requests.get(adresURL)
soup = BeautifulSoup(res.text, 'html.parser')
data = soup.select('.details-property-value')
print(data)

as a result I'm receiving:

[<div class="details-property-value" tabindex="0">{{selectedRecord[commonColumns[index]] || '-'}}</div>]

Any ideas how to get value of fields ? Am i missing sth ?

1 Answers

I'm guessing you're trying to scrape the table on that page. It looks like there is some JSON baked into the HTML:

import requests
from bs4 import BeautifulSoup
import json

url = "https://www.gov.pl/web/koronawirus/wykaz-zarazen-koronawirusem-sars-cov-2"

response = requests.get(url)
response.raise_for_status()

soup = BeautifulSoup(response.content, "html.parser")

data = json.loads(soup.find("pre", {"id": "registerData"}).text)
print(data)
Related