今天寫一個自動登入/登出 ptt
不過這個只限一個帳號登入
不能重複登入
用在python 3.5多寫
可以訊練telnet中文登入界面
還有新帳號要多登入才能po文.用這還挺簡單
code如下:
import telnetlib import sys import time host = 'ptt.cc' user = 'user' password = 'passeord' TA='q' telnet = telnetlib.Telnet(host,port=23,timeout=400) time.sleep(1) content = telnet.read_very_eager().decode('big5', 'ignore') print(content) if u"請輸入代號,或以 guest 參觀,或以 new 註冊:" in content: telnet.write((user+"\r\n").encode('big5')) content = telnet.read_very_eager().decode('big5', 'ignore') time.sleep(1) content = telnet.read_very_eager().decode('big5', 'ignore') print(content) if u"請輸入您的密碼: " in content: print ("輸入密碼中...") telnet.write((password + "\r\n").encode('big5')) time.sleep(1) content = telnet.read_very_eager().decode('big5', 'ignore') print(content) if u'登入中,請稍候...' in content: if u"請按任意鍵繼續" in content: print("資訊頁面,按任意鍵繼續...") for i in range(5): telnet.write(b"q\n") time.sleep(2) content = telnet.read_very_eager().decode('big5', 'ignore') print(content) telnet.write(b"G\n") print(content) telnet.write(b"Y\r\n") time.sleep(1) content = telnet.read_very_eager().decode('big5', 'ignore') print (content)
全站熱搜
留言列表