简体   繁体   English

BeautifulSoup:终端输出在不同的行中

[英]BeautifulSoup : Terminal output are in different lines

I want that the all the beautiful soup output should be in one line rather in a newline我希望所有漂亮的汤输出都应该在一行中而不是在换行符中

HTML: 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',' '))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM