Reputation: 55
I've tried to write data to a csv file using python:
soup = BeautifulSoup(html)
ticketCount=soup.find_all('span',id='ticket_count')
records.append(ticketCount)
But what I got is:
<span id=""ticket_count"">15695.3\n \u4e07\n </span>]
there are some annoying '\n' in the text, how can I get rid of them and make my output more elegant?
Upvotes: 1
Views: 1068
Reputation: 473863
Use get_text(strip=True)
:
from bs4 import BeautifulSoup
soup = BeautifulSoup(html)
ticketCount = soup.find('span', id='ticket_count').get_text(strip=True)
print(ticketCount)
Upvotes: 2