如何使用 selenium.py 获取状态码(python 代码) [英] How to get status code by using selenium.py (python code)

查看:925
本文介绍了如何使用 selenium.py 获取状态码(python 代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 python 写一个 selenium 脚本,但我想我没有看到关于以下内容的任何信息:

I am writing a selenium script by python, but I think I don't see any information about:

如何从 selenium Python 代码中获取 http 状态代码.

或者我错过了什么.如果有人发现了,请随时发布.

Or I missing something. If anyone found that, please feel free to post.

推荐答案

这是不可能的.

不幸的是,Selenium 并没有按照设计提供这些信息.对此有一个非常冗长的讨论,但简短的是:

  1. Selenium 是浏览器模拟工具,不一定是测试工具.
  2. Selenium 在呈现页面并为其添加接口的过程中执行许多 GET 和 POST 操作,这会使 API 以作者抵制的方式复杂化.
  1. Selenium is a browser emulation tool, not necessarily a testing tool.
  2. Selenium performs many GETs and POSTs during the process of rendering a page and adding an interface for that would complicate the API in ways the authors resist.

我们还剩下一些黑客:

  1. 在返回的 HTML 中查找错误信息.
  2. 使用其他工具代替 Requests(但请参阅 @Zeinab 的回答中该方法的缺点.

这篇关于如何使用 selenium.py 获取状态码(python 代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆