Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I get rid of "^M" in data I have scraped from a website?

Tags:

python

html

I have data that looks like this:

"1964   iwanttoholdyourhand beatles



^M

oh yeah, i'll tell you something
i think you'll understand
when i'll say that something
i wanna hold your hand
i wanna hold your hand
i wanna hold your hand

oh please, say to me
you'll let me be your man
and please, say to me
you'll let me hold your hand
i'll let me hold your hand
i wanna hold your hand"

and I'm trying to get rid of the ^M, so I tried using a re.sub but that doesn't find it - I think is some special character and not actually a "^" and "M" next to each other. any ideas on how to remove it? Thanks!

like image 623
WM1 Avatar asked Nov 22 '25 16:11

WM1


1 Answers

^M is used to represent the carriage return character in many editors. You would typically type Ctrl + M to generate that character in those editors.

Python represents this as '\r', as do most programming languages.

like image 142
Michael Greene Avatar answered Nov 24 '25 05:11

Michael Greene



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!