无法使用Python请求会话模块登录网站

时间:2019-07-22 18:02:46

标签: python python-3.x web-scraping python-requests

我刚刚开始进行一些网络爬虫。不幸的是,我尝试使用以下代码访问http://.classic.comunio.de

self.session = requests.session()
payload = {'login': self.username ,
           'pass': self.password,
           'action': 'login'}

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain",
               "User-Agent": user_agent}

req = self.session.post('http://'+self.domain+'/login.phtml',headers=headers,data=payload).content

我已检查http://classic.comunio.de有关用户名,密码和操作的名称。那应该是对的。用户名和密码也正确。

但是,当我尝试登录时却无法转发到下一页,或者无法获取用户个人资料的内容,登录后应该可以实现。

感谢所有帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

尝试使用标头,该页面可能会找到您的脚本作为机器人并将其阻止。以下代码对我来说效果很好:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    /*this is me just messing around and learning*/;
    int health=100;
    while (health>0)
        printf("player has %d HP\n",health);
    health=health-50;
    printf("player took -50 damage ");
    printf("player has %d HP\n",health);
    if(health<20)
        (printf("low on health?"));
    else
        printf("that will leave a mark");
    return 0;
}
相关问题