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

227
Views
How can I print the first text inside a tag

I have a soup object like:

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

I did:

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

Result: 2 633 q.

How can I get without 'q'. Just: 2 633

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The reason is .text gives you all the strings inside the tag concatenated. You should use next_element instead:

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()))

output:

'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!