我尝试用python的库“telnetlib”连接bbs,尝试做一个机器人来回答
消息。当我回复消息时,机器人返回超过 1 条消息。这些是我的
代码。
# -*- coding: cp950 -*-
import telnetlib,random
#f= open("ans.txt","r")
ans = [b"oao", b"xd"]
'''while True:
line = f.readline()
if line = "":
break
ans.append(line)
'''
tn = telnetlib.Telnet("ptt.cc")
tn.read_very_eager()
tn.write(b"*****\r\n") # this is where i enter my username
tn.read_very_eager()
tn.write(b"*****\r\n") # this is wher i enter my password
tn.read_very_eager()
tn.write(b"\r\n")
while True:
if tn.read_very_eager() != "" :
tn.write(b"")
tn.read_very_eager()
tn.write(b"su\r\n")
tn.read_very_eager()
tn.write(b"\r\n")
tn.read_very_eager()
tn.write(b"\r\n\r\n←")
tn.read_very_eager()
tn.read_very_eager()
for i in range(0,1000000):
x = 1