A
A
Alexey2020-11-24 00:17:43
Python
Alexey, 2020-11-24 00:17:43

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

1 answer(s)
S
Sergey Karbivnichy, 2020-11-24
@6alexey9

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}')

5fbc353c3f414147571289.png
You can also pull out some data from there:
5fbc35654a76e868601049.png
Either render js, or get data from json:
5fbc296a033ba367147804.png5fbc2972c05ce925154999.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question