+ 13

How to convert special characters into HTML entities?

I want to convert an arbitrary text into a text with the corresponding HTML-entities and I am searching for a dedicated Python module + method for replacing the special characters into HTML-entities. E.g. the conversion should be like ä -> &auml; ö -> &ouml; ü -> &uuml; ß -> &szlig; I could do this for a couple of characters with a dictionary, but I want to have a comprehensive solution which covers all available characters outside the standard character set a-z and A-Z for many different languages. In the attached file https://code.sololearn.com/cn9CBAh8mLff/?ref=app where I use XML, the '<'-character is automatically converted into its entity &lt;. Why does this not occur with the characters 'äöü'? How would I have to proceed to solve this?

12th Oct 2020, 11:04 PM
Jan Markus
Jan Markus - avatar
2 Answers
+ 7
Not sure if this is correct answer but I think the conversion depends on the browser, in most cases when the browser fails to support some characters, you have to explicitly name it's character set inside the Meta tag <meta charset="utf-something">
13th Oct 2020, 12:05 AM
Mirielle - avatar
+ 5
I don't know it is correct answer or not. Find starting and ending number for all characters. from https://html-css-js.com/html/character-codes/ then use for loop to get all characters. https://code.sololearn.com/WcB3dPe9TxHg/?ref=app
12th Oct 2020, 11:14 PM
🇮🇳Vivek🇮🇳 - avatar