作者peanut97 (花生)
看板Python
标题Re: 新手想写登入BBS的程式(Python 3)
时间Thu Nov 21 02:41:31 2013
这是写好的Python程式,给大家参考。如果有写不好的地方欢迎前辈指点
https://gist.github.com/anonymous/7568323
import telnetlib
import sys
import Account #My file. It contains Account.id, Account.password
import time
tn = telnetlib.Telnet('ptt.cc')
time.sleep(1)
content = tn.read_very_eager().decode('big5','ignore')
print("首页显示...")
if "请输入代号" in content:
print("输入帐号...")
tn.write((Account.id+"\r\n").encode('big5') )
time.sleep(1)
content = tn.read_very_eager().decode('big5','ignore')
print("输入密码...")
tn.write((Account.password+"\r\n").encode('big5'))
time.sleep(2)
content = tn.read_very_eager().decode('big5','ignore')
if "密码不对" in content:
print("密码不对或无此帐号。程式结束")
sys.exit()
if "您想删除其他重复登入的连线吗" in content:
print("发现重复连线,删除他...")
tn.write("y\r\n".encode('big5') )
time.sleep(7)
content = tn.read_very_eager().decode('big5','ignore')
#print(content)
while "任意键" in content:
print("资讯页面,按任意键继续...")
tn.write("\r\n".encode('big5') )
time.sleep(2)
content = tn.read_very_eager().decode('big5','ignore')
if "要删除以上错误尝试" in content:
print("发现尝试登入却失败资讯,是否删除?(Y/N):",end= "")
anser = input("")
tn.write((anser+"\r\n").encode('big5') )
time.sleep(1)
content = tn.read_very_eager().decode('big5','ignore')
print("----------------------------------------------")
print("----------- 登入完成,显示操作介面--------------")
print("----------------------------------------------")
print(content)
print("\n\n\n\n\n\n\n")
print("----------------------------------------------")
print("------------------- 登出----------------------")
print("----------------------------------------------")
tn.write("qqqqqqqqqg\r\ny\r\n".encode('big5') )
time.sleep(1)
content = tn.read_very_eager().decode('big5','ignore')
print(content)
tn.write("\r\n".encode('big5') )
else:
print("没有可输入帐号的栏位,网站可能挂了")
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.24.63.240
1F:推 azurewings:推! 11/21 12:17
2F:→ s860134:其实我也有写过一个 我记得直接print出文章是乱码 11/25 01:22
3F:→ s860134:当时我是用人家弄好的UAO去decode就会出现正常的控制码 11/25 02:13
5F:→ s860134:我印象中第一次找的不是这样网站XD 不过内容好像一样 11/25 02:16