Answer the question
In order to leave comments, you need to log in
Through the site I see the content of the tag, the parser does not see, what's the problem?
First I’ll explain, I need to parse the weather for today and the next day, for today I did it, but the next day I didn’t.
id="bd2c" is a tab with information about the weather on the 6th, that's what I need.(today 5
) or I’ll open a link that opens a tab with the weather on the 6th, at the moment it’s this one
https://sinoptik.com.ru/weather-sinelnikovo-303024...
It would seem that everything can be put in this url for requests and parsed, but there is no parser sees it so
repeat I need to see
<div class="Tab" id="bd2c">что здесь находится</div>
Answer the question
In order to leave comments, you need to log in
better track where the js downloads data from
and download directly (do not forget to disguise yourself as a browser of course)
The weather does not need to be parsed for this there is an API https://openweathermap.org/api. There is also a ready-made library for python https://github.com/csparpa/pyowm
On requests, you can do this, you just need to register to get the APIKEY.
City search:
import requests
s_city = "Petersburg,RU"
city_id = 0
appid = "APIKEY полученный после регистрации по ссылке https://home.openweathermap.org/users/sign_up"
try:
res = requests.get("http://api.openweathermap.org/data/2.5/find",
params={'q': s_city, 'type': 'like', 'units': 'metric', 'APPID': appid})
data = res.json()
cities = ["{} ({})".format(d['name'], d['sys']['country'])
for d in data['list']]
print("city:", cities)
city_id = data['list'][0]['id']
print('city_id=', city_id)
except Exception as e:
print("Exception (find):", e)
pass
try:
res = requests.get("http://api.openweathermap.org/data/2.5/weather",
params={'id': city_id, 'units': 'metric', 'lang': 'ru', 'APPID': appid})
data = res.json()
print("conditions:", data['weather'][0]['description'])
print("temp:", data['main']['temp'])
print("temp_min:", data['main']['temp_min'])
print("temp_max:", data['main']['temp_max'])
except Exception as e:
print("Exception (weather):", e)
pass
try:
res = requests.get("http://api.openweathermap.org/data/2.5/forecast",
params={'id': city_id, 'units': 'metric', 'lang': 'ru', 'APPID': appid})
data = res.json()
for i in data['list']:
print( i['dt_txt'], '{0:+3.0f}'.format(i['main']['temp']), i['weather'][0]['description'] )
except Exception as e:
print("Exception (forecast):", e)
pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question