Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
85 views
in Technique[技术] by (71.8m points)

Problem removing carriage return in Python

I have been looking around this site searching for how to remove unwanted carriage returns. The solutions I found use strip() or rstrip() to remove them. However these do not seem to work for me. I should also state I am using a Windows machine.

I am scraping data from a site using Selenium and need to remove the carriage returns that are inside a span. I am now accessing the elements content as:

span.text.strip()

When I then try to write the line to a file it does not seem to remove all carriage returns. I pasted one of the problematic entries into an online tool to see non-printable characters and it shows: enter image description here

2 of the problematic strings after running them through repr().

Mijn katten zijn verlekkerd op natvoer . Voornamelijk dat van Whiskas . Helaas is dat vaak kostelijk waardoor de kosten hoog oplopen. Dankzij deze actie op bol.com was het betaalbaar en aangenaam om aan te kopen :-) Zowel natvoer als droogvoer eten ze graag van whiskas :-)

"Dit is het voer dat we bijna altijd aan onze katten geven. Lang geleden dat we het nog ergens anders kochten dan bij Bol, de prijs is echt goed voor zo'n grote hoeveelheid voer. Ik vind de zakjes handig omdat het net 1 portie is, je zit dus niet met een blik dat je in de ijskast moet bewaren omdat het niet op is."

It seems there is still a in them...

question from:https://stackoverflow.com/questions/65886046/problem-removing-carriage-return-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...