파이썬에서 HTML api로 받아온 스트링의 특수문자가 HTML entity로 표시되는 상황이 있는데 이걸 다시 돌리는 (unescape)하는 방법을 알아본다. (HTML entity란 것은 HTML에서 특수문자를 표시하게 되면 브라우저에서 인식할 때 태그들의 조합을 섞은 형태로 바꿔서 이해하는 것으로 보면 될 듯 하다)
- HTML entity에 대한 사이트
https://www.w3schools.com/html/html_entities.asp
W3Schools.com
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
www.w3schools.com
추가로 이렇게 쓰여진 것을 사람이 인식할 수 있는 특수문자로 unescape 시키는 웹 사이트도 있어서 링크를 올려둔다
https://www.freeformatter.com/html-escape.html
Free Online HTML Escape / Unescape Tool - FreeFormatter.com
www.freeformatter.com
이제 파이썬에서 unescape하는 코드를 알아보자
import html
new_text = html.unescape("test")
간단하게 html을 import 하고 unescape를 하면 된다고 함
'Devs > Python' 카테고리의 다른 글
[Python] Environment Variables (0) | 2025.04.11 |
---|---|
[Python] Dynamic Typing, Type Hint (0) | 2025.04.10 |
[Python] API (1) | 2025.04.09 |
[Python] SMTP (0) | 2025.04.09 |
[Python] datetime 사용법 (0) | 2025.04.09 |