如何在python get请求中获取aspx表单数据?

2024-09-29 20:32:42 发布

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

我刚刚开始python之旅,所以可能在这里犯了一个基本的错误。这只是我用来学习的一个个人项目。我通过post请求将登录凭据传递给aspx表单,然后尝试对输出运行get请求。但是,通过浏览器访问时表中显示的表单数据没有显示在通过python返回的get请求html输出中。我还缺什么吗?代码如下,删除个人登录信息以保护隐私

from bs4 import BeautifulSoup
import requests


data = {'ctl00$ContentPlaceHolder1$txtUsername': 'username',
        'ctl00$ContentPlaceHolder1$txtPassword': 'pwd',
        'ctl00$ContentPlaceHolder1$btnlogon': 'Logon'}

with requests.Session() as s:
    page = s.get(
        'https://aces2.lsac.org/YourStatus/membership/AppStatIdMe.aspx?guid=CME66wzcsZ0%3D')
    soup = BeautifulSoup(page.content)
    data["___VIEWSTATE"] = soup.select_one("#__VIEWSTATE")["value"]
    data["__VIEWSTATEGENERATOR"] = soup.select_one(
        "#__VIEWSTATEGENERATOR")["value"]
    data["__EVENTVALIDATION"] = soup.select_one("#__EVENTVALIDATION")["value"]
    s.post(
        'https://aces2.lsac.org/YourStatus/membership/AppStatIdMe.aspx?guid=CME66wzcsZ0%3D',
        data=data)
    open_page = s.get(
        "https://aces2.lsac.org/YourStatus/AppStatus/AppOnlineStatus.aspx",
        headers={
            'Accept': 'text / html, application / xhtml + xml, application / xml; q=0.9, image / avif, image / webp, image / apng, * / *; q=0.8, application / signed - exchange; v=b3; q=0.9',
            'Referer': 'https://aces2.lsac.org/YourStatus/membership/logon.aspx',
            'Accept-Encoding': 'gzip, deflate, br'})

    print(open_page.text)

Tags: httpsorgdatagetpageselectonemembership

热门问题