Answer the question
In order to leave comments, you need to log in
How to get a data array?
Here is a site where the graph for the current day is displayed:
https://ua.energy/diyalnist/dyspetcherska-informat...
if you look in the inspector, you can pull out the data (open the inspector, change the date, see the response of the Ajax request).
But it's only for one day.
I need to take away such data for 5 years.
Tell me how can this be done? (of course, I tried the post request in postman, it didn’t work)
ZYZH Maybe you can choose days with tools for testers?
Answer the question
In order to leave comments, you need to log in
The simplest python script
import requests
import datetime
import time
header = {
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36',
'Content-Type':'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language':'ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3',
'Accept-Encoding':'gzip, deflate',
'Connection':'keep-alive',
'Referer': 'https://ua.energy/diyalnist/dyspetcherska-informatsiya/dobovyj-grafik-vyrobnytstva-spozhyvannya-e-e/',
}
# с 01.01.2015 на 30 дней, но даты и количество дней можно поставить любые
start_date = datetime.datetime.strptime('01.01.2015', '%d.%m.%Y').date()
current_date = start_date
for im in range(30):
print(current_date)
data = {
'action': 'get_data_oes',
'report_date': current_date.strftime('%d.%m.%Y'),
'type': 'day',
'rnd': 0.9491192560491961
}
response = requests.post('https://ua.energy/wp-admin/admin-ajax.php', data=data, headers=header)
with open(f"energy_{current_date.strftime('%d%m%Y')}.json", "w+") as file:
file.write(response.text)
current_date += datetime.timedelta(days=1)
time.sleep(1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question