Python Forum
Remove escape characters / Unicode characters from string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove escape characters / Unicode characters from string
#6
Maybe there is better way if could have looked at source or maybe not.
Can take quick run on that string data,as i have clean up much worse stuff that this Wink
>>> s = '\"text_with_blanks\":\"<b>Tagesmen\\u00fc im Restaurant<\\\/b><br\\\/>\\u00a0Samstag, 12. August<br\\\/>\\u00a0<b>Suppen<\\\/b><br\\\/>Tomatensuppe \\u00a0 \\u00a0' 
>>> ss = s.replace('\\u00a0', '').replace('\\\\', '').strip()
>>> ss = d.replace('\\u00fc', '\u00fc')
>>> print(ss)
"text_with_blanks":"<b>Tagesmenü im Restaurant</b><br/>Samstag, 12. August<br/><b>Suppen</b><br/>Tomatensuppe

# Now need a parser
>>> from bs4 import BeautifulSoup
>>>
>>> soup = BeautifulSoup(ss, 'lxml')
>>> print(soup.prettify())
<html>
 <body>
  <p>
   "text_with_blanks":"
   <b>
    Tagesmenü im Restaurant
   </b>
   <br/>
   Samstag, 12. August
   <br/>
   <b>
    Suppen
   </b>
   <br/>
   Tomatensuppe
  </p>
 </body>
</html>

>>> soup.select_one('p > b')
<b>Tagesmenü im Restaurant</b>
>>> print(soup.select_one('p > b').text)
Tagesmenü im Restaurant
Reply


Messages In This Thread
RE: Remove escape characters / Unicode characters from string - by snippsat - May-15-2020, 01:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy xml content from webpage and save to locally without special characters Nik1811 14 616 Mar-26-2024, 09:28 AM
Last Post: Nik1811
  remove gilberishs from a "string" kucingkembar 2 203 Mar-15-2024, 08:51 AM
Last Post: kucingkembar
  sort search results by similarity of characters jacksfrustration 5 367 Feb-16-2024, 11:59 PM
Last Post: deanhystad
  non-latin characters in console from clipboard Johanson 3 656 Oct-26-2023, 10:10 PM
Last Post: deanhystad
Question Special Characters read-write Prisonfeed 1 582 Sep-17-2023, 08:26 PM
Last Post: Gribouillis
  doing string split with 2 or more split characters Skaperen 22 2,322 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,430 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  use of escape character in re.sub and find WJSwan 1 877 Feb-16-2023, 05:19 PM
Last Post: Larz60+
  How to remove patterns of characters from text aaander 4 1,084 Nov-19-2022, 03:34 PM
Last Post: snippsat
Smile please help me remove error for string.strip() jamie_01 3 1,151 Oct-14-2022, 07:48 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020