I want that the all the beautiful soup output should be in one line rather in a newline
HTML:
<h1 class="page-title nosp" data-price-promise-enabled="">
<span>SAMSUNG</span>
<span>QE43Q60RATXXU 43" Smart 4K Ultra HD HDR QLED TV with Bixby</span>
</h1>
Code:
try:
title = soup.find('h1', attrs={'class':'page-title nosp'}).text
except:
title = None
Terminal:
PS C:\Users\Zandrio> & C:/Users/Zandrio/AppData/Local/Programs/Python/Python38/python.exe "c:/Users/Zandrio/Documents/Advanced Project/Proxy/currys.py"
SAMSUNG
QE43Q60RATXXU 43" Smart 4K Ultra HD HDR QLED TV with Bixby
I want output without a whitespace or newline
SAMSUNG QE43Q60RATXXU 43" Smart 4K Ultra HD HDR QLED TV with Bixby
尝试
print(title.strip().replace('\n',' '))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.