K
K
Kirieshka3x2020-04-16 13:17:16
Python
Kirieshka3x, 2020-04-16 13:17:16

What is this error?

'NoneType' object has no attribute 'text'
used to run.
the code:

tomsk = "https://yandex.ru/search/?text=%D0%BF%D0%BE%D0%B3%D0%BE%D0%B4%D0%B0%20%D0%B2%20%D1%82%D0%BE%D0%BC%D1%81%D0%BA%D0%B5&lr=67"
full_page_tomsk = requests.get(tomsk)
soup_tomsk = BeautifulSoup(full_page_tomsk.content, "html.parser")
div_tomsk = soup_tomsk.find('div', {"class":"weather-forecast__current-temp"})
print(div_tomsk.text)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2020-04-16
@Kirieshka3x

The div_tomsk variable is empty.

S
Sergey Grebennikov, 2020-04-16
@SergeyGrebennikov

With this url, the requests.get() method is protected from bots.
1. Before executing requests.get(), try to fill Requests Headers with the data that Chrome sends, for example, when accessing Yandex.
2. Change the url intended for searching information about the weather in Tomsk to " https://yandex.ru/pogoda/tomsk " and, of course, the parameters for highlighting the temperature.
3. If the blocking works, then I advise you to use the silenium module (browser control from your program)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question