H
H
hoogierain2020-10-01 02:43:20
Python
hoogierain, 2020-10-01 02:43:20

How to display text when parsing?

How do I output "word" if it's not in "Class"? What should I enter in the "Class" column? Sorry if this is a dumb question, I've only been programming for 4 days..
5f7516e3d4fa3038382406.png
soup = BeautifulSoup(resp, 'html.parser')
divs = soup.find('div', class_='result-shield-container tlid-copy-target')
appeals = soup.find_all('span', class_='tlid-translation translation')
bot.send_message(message.chat.id, appeals.get_text(''))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alyasaev, 2020-10-01
@alyasaev

bot.send_message(message.chat.id, appeals[0].text) should help if memory serves

V
Valery Mamontov, 2020-10-01
@vmamontov

hoogierain

# если такой класс встречается в html-коде только ОДИН раз, то код такой:
soup = BeautifulSoup(resp, 'html.parser')
appeals = soup.find('span', {'class': 'tlid-translation translation'}).get_text().strip()
bot.send_message(message.chat.id, appeals)

# если НЕСКОЛЬКО раз, то код такой:
soup = BeautifulSoup(resp, 'html.parser')
appeals = [s.get_text().strip() for s in soup.find_all('span', {'class': 'tlid-translation translation'})]
for app in appeals:
  bot.send_message(message.chat.id, app)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question