Charlie Specter
Charlie Specter

Reputation: 23

HTML string decode in python

How to decode this string in python?

title = 'Fast & Furious 6'

to get:

Fast & Furious 6

Thank you!

Upvotes: 2

Views: 124

Answers (2)

MarianD
MarianD

Reputation: 14191

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).

Upvotes: 0

Daniele
Daniele

Reputation: 724

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)

Upvotes: 1

Related Questions