作者peanut97 (花生)
看板Python
标题Re: 新手想写登入BBS的程式
时间Tue Nov 19 17:52:08 2013
我又做了新的测试:
程式码:
===============================================
# -*- 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
1F:推 icycandle:等等,你是用python2还是python3? 11/19 19:11
2F:→ peanut97:python3 ~ 11/19 19:14
※ 编辑: peanut97 来自: 60.248.161.28 (11/19 19:14)