R
R
rink02018-03-05 22:32:52
Python
rink0, 2018-03-05 22:32:52

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
5a9d9bb79c2d7599501376.png
repeat I need to see

<div class="Tab" id="bd2c">что здесь находится</div>

And I'll show you how the computer sees it,
5a9d9b553660e148922483.png
please help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-03-05
@rink0

better track where the js downloads data from
and download directly (do not forget to disguise yourself as a browser of course)

A
asd111, 2018-03-06
@asd111

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

Current weather :
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

Forecast for 5 days:
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 question

Ask a Question

731 491 924 answers to any question