[問題] unicode to big5

看板Python作者 (HIHIHI)時間14年前 (2011/06/18 22:17), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串1/1
問一個笨問題 t=u'\u6211' print t --> 我 如果有一網頁上有 \u6211 這樣的字串,那如何抓下來後轉成big5呢 response = urllib2.urlopen(... html=response.read() html --> '\\u6211' print html.encode('big5','ignore') --> '\u6211' 要如何得到"我"呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.161.246.198

06/18 23:17, , 1F
html.decode('unicode_escape').encode('big5')
06/18 23:17, 1F

06/18 23:17, , 2F
eval('u"%s"'%html)
06/18 23:17, 2F

06/18 23:45, , 3F
好奇問一下,為什麼會想要轉成big-5 ?
06/18 23:45, 3F
文章代碼(AID): #1D_BDgu1 (Python)
文章代碼(AID): #1D_BDgu1 (Python)