-
Notifications
You must be signed in to change notification settings - Fork 0
/
gismeteo.py
66 lines (55 loc) · 2 KB
/
gismeteo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from bs4 import BeautifulSoup
import requests
import json
import fake_useragent
url = 'https://www.gismeteo.ru/'
ua = fake_useragent.UserAgent()
headers = {
"User-Agent": ua.random,
'Accept': '*/*'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'lxml')
# Название города
list = []
city = soup.find_all('div', class_='city')
for i in city:
city_name = i.find('a', class_='city-link link')
res_head = {}
list.append(res_head)
# Основная информация о погоде
main = soup.find_all('div', class_='frame-now')
for j in main:
city_time = j.find('div', class_='current-time').text.strip()
temperature = j.find('div', class_='weather-info-header').text.strip()
it_feels_like = j.find('div', class_='weather-item weather-feeling').text.strip()
wind = j.find('div', class_='weather-item weather-wind').text.strip()
pressure = j.find('div', class_='weather-item weather-pressure').text.strip()
humidity = j.find('div', class_='weather-item weather-humidity').text.strip()
gm_activity = j.find('div', class_='weather-item weather-geomagnetic').text.strip()
water = j.find('div', class_='weather-item weather-water').text.strip()
res_main = {
'city_time': city_time,
'temperature': temperature,
'it_feels_like': it_feels_like,
'wind': wind,
'pressure': pressure,
'humidity': humidity,
'gm_activity': gm_activity,
'water': water
}
list.append(res_main)
fot = soup.find_all('div', class_='frame-forecast')
for y in fot:
times = y.find('div', class_='widget-row widget-row-time').text
for z in y.find_all('span', class_='unit unit_temperature_c'):
temp = z.text
wind = y.find('span', class_='wind-unit unit unit_wind_m_s').text
res_fot = {
'times': times,
'temp': temp,
'wind_m/s': wind
}
list.append(res_fot)
print(res_fot)