반응형
URL에서 이스케이프 된 문자 디코딩
이스케이프 문자가있는 URL이 포함 된 목록이 있습니다. 이러한 문자는 urllib2.urlopenhtml 페이지를 복구 할 때 설정되었습니다 .
http://www.sample1webpage.com/index.php?title=%E9%A6%96%E9%A1%B5&action=edit
http://www.sample1webpage.com/index.php?title=%E9%A6%96%E9%A1%B5&action=history
http://www.sample1webpage.com/index.php?title=%E9%A6%96%E9%A1%B5&variant=zh
파이썬에서 이스케이프되지 않은 형태로 다시 변환하는 방법이 있습니까?
추신 : URL은 utf-8로 인코딩됩니다.
urllib.unquote(끈)
%xx이스케이프를 해당하는 단일 문자로 바꿉니다 .예 :
unquote('/%7Econnolly/')수율'/~connolly/'.
그리고 디코딩 만하면됩니다.
업데이트 : Python 3의 경우 다음을 작성합니다.
urllib.parse.unquote(url)
그리고 사용하는 경우 다음을 사용할 Python3수 있습니다.
urllib.parse.unquote(url)
또는 urllib.unquote_plus
>>> import urllib
>>> urllib.unquote('erythrocyte+membrane+protein+1%2C+PfEMP1+%28VAR%29')
'erythrocyte+membrane+protein+1,+PfEMP1+(VAR)'
>>> urllib.unquote_plus('erythrocyte+membrane+protein+1%2C+PfEMP1+%28VAR%29')
'erythrocyte membrane protein 1, PfEMP1 (VAR)'
당신이 사용할 수있는 urllib.unquote
import re
def unquote(url):
return re.compile('%([0-9a-fA-F]{2})',re.M).sub(lambda m: chr(int(m.group(1),16)), url)
참고 URL : https://stackoverflow.com/questions/8136788/decode-escaped-characters-in-url
반응형
'IT박스' 카테고리의 다른 글
| MySQL 업데이트 CASE WHEN / THEN / ELSE (0) | 2020.10.26 |
|---|---|
| Google Analytics analytics.js 예외 추적에서 예외보고 (0) | 2020.10.26 |
| jQuery Mobile : 동적으로 추가 된 콘텐츠의 마크 업 향상 (0) | 2020.10.26 |
| React Native에서 기본 글꼴 패밀리를 설정하는 방법은 무엇입니까? (0) | 2020.10.26 |
| 데이터 흐름 프로그래밍 언어 (0) | 2020.10.26 |