网站不允许访问[使用请求单击链接]

2024-03-28 11:31:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在我的大学ID的仪表板页面上创建一个链接(考勤链接)(在我创建了一个脚本以使用请求登录到网站之后)。你知道吗

我得到链接的href并将其附加到网页的主URL,即href如下所示:

../Student/StudentAttendanceView.aspx?SID=d5ZJjDPElr2gLui0QuBhtA==|KfGEwXYb8QU=

以及地址栏上链接的URL:

http://erp.college_name.edu/Student/StudentAttendanceView.aspx?SID=d5ZJjDPElr2gLui0QuBhtA==|KfGEwXYb8QU=

所以在从href中移除两个..之后,我将它附加到http://erp.college_name.edu。你知道吗

问题是,当我试图从链接中获取source-code-text时,网站不允许我这样做,而不是源代码(考勤链接页),我得到以下结果:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Index</title>
    </head>

    <body>
        <center><img src="images/stop-sign-small2.jpg" /></center>
    </body>
</html>

有什么问题?为什么网站不允许我这么做?我还在分析登录时的头文件和一些附加信息,但仍然无法访问:

这个问题和我之前关于这个项目的问题in case you want to relate有关。我怎样才能解决这个问题?你知道吗

代码是:

import requests
from bs4 import BeautifulSoup

url = 'http://erp.college_name.edu/'

start = requests.session()
token = '3BA8C6EB'
token_1 = 'value'
stuff = {
    'tbUserName': 'my_usrname',
    'tbPassword': 'my_pass',
    '__VIEWSTATEGENERATOR': ''.join(token),
    'btnLogIn': 'Login',
    '__VIEWSTATE' : ''.join(token_1),
}

new_stuff = {
             '__EVENTTARGET' : '',
             '__EVENTARGUMENT': '',
             '__VIEWSTATE': 'value',
             'tbUserName': 'my_username',
             'tbPassword': 'my_pass',
             '__VIEWSTATEGENERATOR': '791C70D1',
             'btnLogIn': 'Login',
            }

opens = start.post(url=url, data=stuff)
soup = BeautifulSoup(opens.text, 'lxml')

for I in soup.find_all('div', class_='lPanel'):
    L = 'http://erp.college_name.edu' + str(I.findAll('li')
    [4].a.get('href')
    [2:])
    attendance = start.get(url=L, headers=new_stuff, data=stuff)
    print(attendance)

Tags: nametokenhttpurlerp网站链接my