2

How to decode this string in python?

title = 'Fast & Furious 6'

to get:

Fast & Furious 6

Thank you!

1
  • That is HTML encoded not XML. Commented Oct 15, 2017 at 22:47

2 Answers 2

1

with this code you got char symbol from ascii rappresentation.

title = 'Fast & Furious 6'
title = title[:-1]
substring=[x.strip() for x in title.split(';')]
titleFinal = ''

for ch in substring:
    newstr = ch.replace("&#", "")
    titleFinal+=chr(int(newstr))

print(titleFinal)
Sign up to request clarification or add additional context in comments.

Comments

0

Just use the built-in html module:

import html
decoded_title = html.unescape(title))

as your string consists of HTML-safe sequences (numeric character references).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.