Can you please tell me how to pull the data from the following code?
<div class="day"> <a href="/prognoz/semipalatinsk/14dney/#day2" class="day__link" name="clb3279967"> <div class="day__date">Завтра</div> <div class="weather-icon weather-icon_05 margin-bottom-10" title="переменная облачность"></div> <div class="day__temperature" title="Днем">+9° <span class="day__temperature__night" title="Ночью">0°</span> </div> <div class="day__description" Piton parser such
import requests, bs4 s=requests.get('https://pogoda.mail.ru/prognoz/semipalatinsk/') b=bs4.BeautifulSoup(s.text, "html.parser") p3=b.select('.day__date') pogoda1=p3[0].getText() p4=b.select('.day .day__temperature') pogoda2=p4[0].getText() p5=b.select('.day__temperature__night') pogoda3=p5[0].getText() p6=b.select('.day__description') pogoda4=p6[0].getText() print(pogoda1 + ' ' + pogoda2 + ' ' + pogoda3 + ' ' + pogoda4) Code output
> Завтра +9° > 0° > 0° облачно`` And you need to be so
> Завтра +9° 0° облачно I understand that the problem arises because of the span inside the class day__temperature . But how to drop it is not clear.
div.day__temperatureall text fromdiv.day__temperature? (then for example, the strip_strings attribute can be used 2- you can select_one () use 3- requests can use the wrong encoding (s.text). change, see if there is an explicit API for the site (or its sources, analogues) that allows you to get the necessary information - jfsfind()works exactly as it should work and returns exactly the result that is shown in the response. You decide what you really want to get in the end and update the question. - jfs