2016-09-17 26 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秒后才能登录。是什么赋予了?我可以手动更快地登录。 –

相关问题