Answer the question
In order to leave comments, you need to log in
How to limit BeautifulSoup's data parsing and collect only certain values?
The site has start and end times. I make a request for a page with information about pairs for a specific day, and display it to the user in a telegram bot using the aiogram library. The problem is that the information for each day is always under the same class attribute value. It's easier to show with an example.
Here information is only about the 3rd and 4th pair, because there are no others on this day:
<td><div>Пн</div><div class="mh-50 cell cell-vertical"><span class="lesson">3 пара</span><span class="start">11:45</span><span class="finish">13:20</span></div><div class="mh-50 cell cell-vertical"><span class="lesson">4 пара</span><span class="start">13:30</span><span class="finish">15:05</span></div></td>
<td><div>Вт</div><div class="mh-50 cell cell-vertical"><span class="lesson">1 пара</span><span class="start">08:00</span><span class="finish">09:35</span></div><div class="mh-50 cell cell-vertical"><span class="lesson">2 пара</span><span class="start">09:45</span><span class="finish">11:20</span></div><div class="mh-50 cell cell-vertical"><span class="lesson">3 пара</span><span class="start">11:45</span><span class="finish">13:20</span></div><div class="mh-50 cell cell-vertical"><span class="lesson">4 пара</span><span class="start">13:30</span><span class="finish">15:05</span></div></td>
<td><div>Ср</div><div class="mh-50 cell cell-vertical"><span class="lesson">1 пара</span><span class="start">08:00</span><span class="finish">09:35</span></div></td>
url = ''
response = requests.get(url)
html = response.text
soup = BeautifulSoup(html, 'lxml')
today = soup.findAll("div", {"class" : "cell mh-50", "data-rel" : "popover", "data-placement" : "right"})
for i in range(0, len(today)):
today_data = today[i]["data-content"].replace("<br>", "")
await bot.send_message(message.from_user.id, today_data)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question