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
  Read characters of line and return positions Gizzmo28 2 153 Nov-04-2020, 09:27 AM
Last Post: perfringo
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 211 Oct-19-2020, 04:16 AM
Last Post: deanhystad
  Print characters in a single line rather than one at a time hhydration 1 221 Oct-10-2020, 10:00 PM
Last Post: bowlofred
  get two characters, count and print from a .txt file Pleiades 9 415 Oct-05-2020, 09:22 AM
Last Post: perfringo
  How to remove char from string?? ridgerunnersjw 2 161 Sep-30-2020, 03:49 PM
Last Post: ridgerunnersjw
  Pressing non-latin characters? Murlog 0 274 Jul-25-2020, 03:10 PM
Last Post: Murlog
  Introduction to escaping characters in strings Geelong_crazy 1 303 Jul-18-2020, 06:58 PM
Last Post: DT2000
  Reading integers from a file; the problem may be the newline characters JRWoodwardMSW 2 382 Jul-14-2020, 02:27 AM
Last Post: bowlofred
  counting characters in an object Skaperen 11 953 Jun-09-2020, 09:22 PM
Last Post: Gribouillis
  How to find the first and last of one of several characters in a list of strings? tadsss 2 386 Jun-02-2020, 05:23 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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