Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录到不使用Python请求模块的网页_Python_Html_Login_Python Requests - Fatal编程技术网

登录到不使用Python请求模块的网页

登录到不使用Python请求模块的网页,python,html,login,python-requests,Python,Html,Login,Python Requests,我试图使用Python请求模块对网站进行身份验证,然后从中检索一些信息。这是页面的登录部分: <div> <label class="label-left" for="username"> … </label> <input id="username" class="inputbox" type="text" size="18" alt="username" name="username"></input> <

我试图使用Python请求模块对网站进行身份验证,然后从中检索一些信息。这是页面的登录部分:

<div>

    <label class="label-left" for="username"> … </label>
    <input id="username" class="inputbox" type="text" size="18" alt="username" name="username"></input>

</div>
<div>

    <label class="label-left" for="passwd"> … </label>
    <input id="passwd" class="inputbox" type="password" alt="password" size="18" name="passwd"></input>

</div>
<div> … </div>
<div class="readon">

    <input class="button" type="submit" value="Login" name="Submit"></input>    
问题是,即使在身份验证之后,我也会得到相同的登录页面。响应代码是200,所以一切都应该正常。我错过什么了吗


更新

多亏了这条评论,我分析了post请求,发现其中有一些隐藏的参数。其中,有一些参数的值在不同的请求之间变化。出于这个原因,我只是使用BeautifulSoup获取它们,然后更新post请求的有效负载,如下所示:

with requests.Session() as s:

    login_page = s.get(login)
    soup = BeautifulSoup(login_page.text)
    inputs = soup.findAll(name='input',type='hidden')

    for el in inputs:
        name = el['name']
        value = el['value']
        payload[name]=value

    s.post(login, data=payload)
    ans = s.get(url)

尽管如此,我仍然得到登录页面。可能还有其他一些影响因素?

是否没有隐藏的输入?您是否尝试在浏览器中手动登录并分析请求参数?我已根据您的评论更新了问题。您是否提供指向该页面的链接?我无法提供指向该页面的链接,但我发现问题在于请求无法从网站获取cookies。如果我自己写cookies并将其传递到帖子中,然后收到请求,那么它就可以工作了。这仍然让我困惑
with requests.Session() as s:

    login_page = s.get(login)
    soup = BeautifulSoup(login_page.text)
    inputs = soup.findAll(name='input',type='hidden')

    for el in inputs:
        name = el['name']
        value = el['value']
        payload[name]=value

    s.post(login, data=payload)
    ans = s.get(url)