gpt4 book ai didi

Python 网络抓取 : dealing with user login popup

转载 作者:行者123 更新时间:2023-12-01 08:53:55 25 4
gpt4 key购买 nike

我看过关于使用漂亮的 soup 和请求模块进行 Python 网络抓取的用户/登录凭据的帖子和 SO 问题,并且当用户/密码框内置到页面中时,解决方案适用。

但是弹出窗口呢?我需要不同的方法吗?

我从这里访问: https://csas.nbme.org/acpweb/servlet/AcpNbmeLogin?entryPoint=1001

然后打开弹出窗口 https://csas.nbme.org/acpweb/servlet/userConnectInfo

显然,我有登录详细信息。我的第一个脚本尝试不起作用。

那么,我还应该采用其他模块或其他方法吗?

谢谢。

最佳答案

您应该首先执行 POST 请求以将凭据发送到 https://csas.nbme.org/acpweb/servlet/AcpUserMain包含这些信息:

dbconnect   y
entryPoint 1001
numblogon 0
password yourpassword
username yourusername

(我使用 Firefox 控制台的“网络”选项卡来查看发送弹出表单时完成了哪个请求)

服务器将向您发送您应该保留的 cookie - 请求模块使用 sessions 可以很好地做到这一点:

The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance

然后您可以转到所需的页面(使用相同的 session 对象)。

代码应如下所示:

import requests

with requests.Session() as s:
s.post('https://csas.nbme.org/acpweb/servlet/AcpUserMain', data = {
'dbconnect': 'y',
'entryPoint': 1001,
'numblogon': 0,
'password': <yourpassword>,
'username': <yourusername>,
})

r = s.get(<url to parse>)

#Use beautifoulsoup on r

关于Python 网络抓取 : dealing with user login popup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52907414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com