Re: 新手想寫登入BBS的程式(Python 3)

看板Python作者 (花生)時間10年前 (2013/11/21 02:41), 編輯推噓1(104)
留言5則, 2人參與, 最新討論串5/5 (看更多)
這是寫好的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

11/21 12:17, , 1F
推!
11/21 12:17, 1F

11/25 01:22, , 2F
其實我也有寫過一個 我記得直接print出文章是亂碼
11/25 01:22, 2F

11/25 02:13, , 3F
當時我是用人家弄好的UAO去decode就會出現正常的控制碼
11/25 02:13, 3F

11/25 02:16, , 4F

11/25 02:16, , 5F
我印象中第一次找的不是這樣網站XD 不過內容好像一樣
11/25 02:16, 5F
文章代碼(AID): #1IZG9V12 (Python)
文章代碼(AID): #1IZG9V12 (Python)