python-3.x - Python 网页抓取 - 为什么总是获取主页源代码?
问题描述
我已经完成了登录的所有初始步骤,能够访问该网站,我正在尝试使用 POST 请求模拟一个搜索操作(实际上是使用门户网站上的提交操作表单完成的),操作成功但页面源我得到的是来自“主页”页面。
我可以理解 100% 页面源代码是否未显示在页面源中(假设使用 生成的数据JavaScript
),但这里的响应页面是静态“主页”页面。
什么是重定向到主页?如何停止导航?
以下是实现此目的的代码步骤:
import requests
session = requests.Session()
session.get(access_config['login-url'])
session.post(access_config["auth-url"], data=auth_config)
res = session.post(link)
print(res.status_code)
print(res.history)
print(res.url)
print(res.text)
回复:
status code :: 200
history :: <html><head><title>302 Moved Temporarily</title></head>
<body bgcolor="#FFFFFF">
<p>This document you requested has moved
temporarily.</p>
<p>It's now at <a href="https://www.xxxx.com/a/welcome.html">https://www.xxxx.com/a/welcome.html</a>.</p>
</body></html>
response URL :: https://www.xxxx.com/a/welcome.html
我正在使用requests
库,我知道很多人使用selenium
库来进行这些操作,有什么我可以使用requests
或除此之外的东西selenium
吗?
解决方案
@SonalBorkar 谢谢!再次
我已经使用“Firefox 检查器”进行了检查,并发现了所见背后的 2 个请求,您可以在图片中看到。
下面的代码完美运行 -
import requests
session = requests.Session()
session.get(access_config['login-url'])
session.post(access_config["auth-url"], data=auth_config)
session.post(link1)
res = session.get(link2)
print(res.status_code)
print(res.history)
print(res.url)
print(res.text)
link1
link2
双击检查员行后可见
link1
--> 双击search.html
link2
--> 双击seriessearch.html?...
推荐阅读
- javascript - p5.js 使用变量改变大小
- dropbox-api - Node-Red Dropbox 节点
- javascript - dot net core 项目,在 site.js 中使用 jquery maxlength 和 count 插件
- pygame - 使用 pygame 更改显示方向
- azure - Azure Active Directory 阻止登录
- sql - SQL求和列中的所有值
- javascript - 为 React 中的常见问题切换获取“TypeError:无法读取未定义的类列表”
- python - 导入模块和运行烧瓶应用程序的正确方法
- c# - Directory.EnumerateFiles 搜索模式不适用于文件共享
- java - 如何让我的对角线从我的星号框的左下方开始打印?