python - 使用 requests.session 登录后无法访问其他站点
问题描述
这是我在这里的第一个问题,我对编程也很陌生,所以请在回答时考虑一下:)
我正在尝试通过 python 创建一个带有“BeautifulSoup”和“请求”的网页抓取工具,用于梦幻德甲游戏,我想在其中收集所有玩家数据。我想我已经设法登录到该站点,但我没有正确登录。我创建了一个会话并使用我的登录信息发送了一个有效负载。之后,我想在需要登录用户的不同页面中做任何我喜欢的事情。但我总是被重定向到主页。
正常的登录页面是https://fantasy.bundesliga.de/?register_or_login=login。使用开发者工具,我找到了正确的 url 来模拟登录为“https://accounts.eu1.gigya.com/accounts.login”。表单数据有很多参数,我不确定如何正确操作它们。在第一次尝试中,我只是从手动登录中复制了参数。但是当我尝试访问另一个网站时,它会将我重定向到主页“https://fantasy.bundesliga.de/”。
到目前为止,这是我的代码:
import requests
from bs4 import BeautifulSoup
payload = {"loginID": "replace with E-Mail",
"password": "replace with password",
"sessionExpiration": "0",
"targetEnv": "jssdk",
"include": "profile,data,emails,subscriptions,preferences,",
"includeUserInfo": "true",
"loginMode": "standard",
"lang": "de",
"APIKey": "3_2B6SeL1zQuVojVM9IlfzLovH7xJLlpUIeSXNPMS0uihudZQtuKy99SfKcrJRtWKo",
"source": "showScreenSet",
"sdk": "js_latest",
"authMode": "cookie",
"pageURL": "https://fantasy.bundesliga.de/",
"format": "json",
}
with requests.Session() as s:
p = s.post("https://accounts.eu1.gigya.com/accounts.login", data = payload)
print(p.url)
f = open("login.txt", "w", encoding="utf-8")
f.write(p.text)
f.close()
r = s.get("https://fantasy.bundesliga.de/match_days/14/lineups/252439")
print(r.url)
login.txt 包含我所有的个人资料信息,所以我已经成功登录。但是最后一行,我想打印 r.url,输出是“https://fantasy.bundesliga.de/”,所以我无法访问我想要的信息。
老实说,我一无所知,因为我在网上找不到这个问题。每个人在登录后似乎都能成功访问他们的页面。
谢谢大家解答!
解决方案
推荐阅读
- ios - 如何在 watchkit 中在睡眠模式下使用定时器
- c++ - 矩形没有正确绘制?
- time-series - 具有多元协变量的 ARIMA 模型?
- laravel - Laravel 会话更改在 2 个页面重新加载/重定向后不会持续存在
- swift - SwiftUI:在 tvOS 上获取当前关注的 NavigationView 项目索引
- .net - Azure 管道 - dotnet 发布覆盖 VSBuild .zip 然后抱怨找不到它们
- python - Python Web 应用程序 - 关于长时间请求的问题
- r - 如何将重复节点修剪到最近的共同祖先?数据树 R
- visual-studio-code - vscode 自动导入 import * as console from 'console'
- java - 将 HTTP 请求中的多个参数发送到 NetBeans 时,我的 @Path 注释有什么问题?