2016-09-17 71 views
0

因此,我決定通過學習一門新的語言並開始構建機器人,來提高自己的編程技能。 「hackthissite.org」有幾個編程挑戰,我想完成。第一個是解讀一些單詞。即使網站顯然是在線,requests.get()方法也會超時

好吧,很簡單。讓我創建一個腳本,首先登錄並隔離這些單詞。

我似乎無法在15秒內連接到該網站。我使用「請求」API來執行此操作。這裏是我的代碼:

def main(): 
print("Starting Prograam") 
session = requests.session() 
session = requests.get("https://www.hackthissite.org/pages/index/index.php") 
print(str(session.status_code)) 
print("Successfully Connected to the site") #TODO: Error Handling 
login = {'username' : 'My Account Username', 'password' : 'Terrible Hard-coded Password Here'} 
session = requests.post("https://www.hackthissite.org/user/login", data=login) 
bs = BeautifulSoup(session.content, "html.parser") 
print(bs.prettify()) 

main() 

程序了十一年跑,我只是最終得到任何超時錯誤或等待一段時間近乎荒謬的,我知道我不應該等待。我似乎無法在網上找到與我一樣的問題。 「hackthissite.org」有反對殭屍程序的東西嗎?我需要以某種方式掩蓋我作爲用戶的活動嗎?

回答

0

你永遠不使用會話首先要創建這樣所有線棒材,最後兩個是無關緊要的,登陸你需要的是你的用戶名,密碼和設置引薦https://www.hackthissite.org

def main(): 
    print("Starting Program") 
    with requests.session() as session: 
     login = {"username": "username", 
       "password": "pass", 
       "btn_submit": "Login"} 
     session.headers.update({"referer":"https://www.hackthissite.org"}) 
     s = session.post("https://www.hackthissite.org/user/login", data=login) 
     bs = BeautifulSoup(s.content, "html.parser") 
     print(bs.prettify()) 

一旦你做了,你會在輸出中看到你的個人資料頁面。

+0

好的,現在我一直登錄,但只有15秒後才能登錄。是什麼賦予了?我可以手動更快地登錄。 –

相關問題