Answer the question
In order to leave comments, you need to log in
Hello, I'm trying to extract data from the site. Through F12 normal. BS4 returns an empty array[]. How to pull data?
import requests
from bs4 import BeautifulSoup
HOST = 'https://xn--80aesfpebagmfblc0a.xn--p1ai/'
URL = 'https://xn--80aesfpebagmfblc0a.xn--p1ai/information/'
HEADERS = {
'accept': '*/*',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'
}
def get_html(url, params=''):
r = requests.get(url, headers=HEADERS, params=params)
return r
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('div', class_='cv-spread-overview__table')
print(items)
html = get_html(URL)
get_content(html.text)
Answer the question
In order to leave comments, you need to log in
Most likely this is a collective farm bike, but it worked for me:
import requests
import json
html = requests.get('https://xn--80aesfpebagmfblc0a.xn--p1ai/information/').text
start = '<cv-spread-overview :spread-data=' # Начало обрезки
end = "isolation-data" # Конец обрезки
raw_json_data = html[html.find(start)+34:html.find(end)-3] # Вырезаем json из html страницы
json_data= json.loads(raw_json_data)
for item in json_data:
title = item['title'] # Город
sick = item['sick'] # Выявлено
healed = item['healed'] # Выздоровело
died = item['died'] # Умерло
sick_incr = item['sick_incr'] # Новые
healed_incr = item['healed_incr'] #В ыздоровело за сутки
died_incr = item['died_incr'] # Умерло за сутки
print(f'{title} - {sick} - {healed} - {died} - {sick_incr} - {healed_incr} - {died_incr}')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question