Re: 新手想寫登入BBS的程式(Python 3)
我又做了新的測試:
程式碼:
===============================================
# -*- coding: big5 -*-
import telnetlib
tn = telnetlib.Telnet('ptt.cc')
s = tn.read_until(b"ptt3")
print(s)
===============================================
會印出ptt的首頁畫面
但改成read_until(b"請輸入代號"),就不行,程式碼:
===============================================
# -*- coding: big5 -*-
import telnetlib
tn = telnetlib.Telnet('ptt.cc')
s = tn.read_until(b"請輸入代號")
print(s)
===============================================
會顯示錯誤:『bytes can only contain ASCII literal characters.』
看read_until的文件,他接受的參數是byte string,所以應把字串轉成byte string
但看程式碼第一行是用big5
是不是指字串:『請輸入代號』已經是big5編碼
所以要想辦法把big5 轉成byte string ?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 1.200.46.75
推
11/19 19:11, , 1F
11/19 19:11, 1F
→
11/19 19:14, , 2F
11/19 19:14, 2F
※ 編輯: peanut97 來自: 60.248.161.28 (11/19 19:14)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 2 之 5 篇):