如何在python selenium-webdriver中获取标头

大卫542:

我正在尝试获取Selenium Webdriver中的标题。类似于以下内容:

>>> import requests
>>> res=requests.get('http://google.com')
>>> print res.headers

我需要使用网络驱动Chrome程序,因为它支持Flash和测试网页所需的其他功能。这是我到目前为止在Selenium中拥有的东西:

from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://login.comcast.net/login?r=comcast.net&s=oauth&continue=https%3A%2F%2Flogin.comcast.net%2Foauth%2Fauthorize%3Fclient_id%3Dxtv-account-selector%26redirect_uri%3Dhttps%3A%2F%2Fxtv-pil.xfinity.com%2Fxtv-authn%2Fxfinity-cb%26response_type%3Dcode%26scope%3Dopenid%2520https%3A%2F%2Flogin.comcast.net%2Fapi%2Flogin%26state%3Dhttps%3A%2F%2Ftv.xfinity.com%2Fpartner-success.html%26prompt%3Dlogin%26response%3D1&reqId=18737431-624b-44cb-adf0-2a85d91bd662&forceAuthn=1&client_id=xtv-account-selector')
driver.find_element_by_css_selector('#user').send_keys('[email protected]')
driver.find_element_by_css_selector('#passwd').send_keys('XXY')
driver.find_element_by_css_selector('#passwd').submit()
print driver.headers ### How to do this?

我看到了其他一些建议,建议运行整个硒服务器以获取此信息(https://github.com/derekargueta/selenium-profiler)。我如何使用与上述类似的Webdriver来获得它?

elethan:

不幸的是,你不能得到硒webdriver的这些信息,你也将能够在不久的将来,似乎任何时候。一段关于该主题的长时间对话的摘录

此功能将不会发生。

根据我从讨论中得出的结论,主要原因在于,WebDriver旨在“驱动浏览器”,并且将API扩展到该主要目标之外,这在开发人员看来将导致整体质量和API的可靠性受到影响。

在许多地方(包括上面链接的对话),我看到了一个建议的潜在解决方法是使用BrowserMob Proxy,该代理可用于捕获HTTP内容,并可以与硒一起使用 -尽管链接的示例未使用Python硒API。似乎确实有一个适用于BrowserMob Proxy的Python包装器,但是由于我从未使用过它,因此我不能保证它的功效。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章