Can't access values in chart on website using BeautifulSoup/Request

Viewed 48

I'm trying to access specific data from following website: https://koronawirusunas.pl/

Looking for the last entry in green chart/columns shown below - 69513. The only place where I found this number is in line 2028 of web source.

This line contains all entries from the chart separated with date. I have no problem with accessing any other numbers in sections in body part, f.e. with:

import requests
from bs4 import BeautifulSoup

source = requests.get('https://koronawirusunas.pl').text
soup = BeautifulSoup(source, 'lxml')

ratio = soup.find('div', class_='col-md-6 col-lg-4 align-bottom').p.span.text

print(r"Aktualny wskaźnik średniej liczby zakażeń na 100tys. osób \ 7 dni: {}".format(ratio))

but I can't get anything from marked part of website. Following code gives me no result:

import requests
from bs4 import BeautifulSoup

source = requests.get('https://koronawirusunas.pl').text
soup = BeautifulSoup(source, 'lxml')

daily_number_of_vaccines = soup.find('var', dataSource_szczepienia=[])
print(daily_number_of_vaccines)

corona.jpg

1 Answers

The value you want can be fetched (along with other values) from a <span> tag that's above the bar chart.

Here's how:

import requests
from bs4 import BeautifulSoup

page = requests.get("https://koronawirusunas.pl/").content
szczepienia = BeautifulSoup(page, "lxml").find_all("span", class_="badge badge-szczepienia")[-1]
print(
    f"Aktualny wskaźnik średniej liczby "
    f"zakażeń na 100tys. osób \ 7 dni: {szczepienia.getText(strip=True)}"
)

Output:

Aktualny wskaźnik średniej liczby zakażeń na 100tys. osób \ 7 dni: 69 513
Related