Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
¿Cómo puedo imprimir el primer texto dentro de una etiqueta?

Tengo un objeto de sopa como:

 <span class="nowrap"> 2 633 <span class="currency rub">q</span> </span>

Hice:

 price = item.find('span', class_='nowrap') price_x = price.text.strip() print(price_x)

Resultado: 2 633 q.

¿Cómo puedo obtener sin 'q'. Sólo: 2 633

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

La razón es que .text te da todas las cadenas dentro de la etiqueta concatenadas. Deberías usar next_element en su lugar:

 from bs4 import BeautifulSoup text = """<span class="nowrap"> 2 633 <span class="currency rub">q</span> </span>""" soup = BeautifulSoup(text, 'html.parser') price = soup.find('span', class_='nowrap') next_element = price.next_element print(repr(next_element.strip()))

producción:

 '2 633'
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!