【发布时间】:2017-02-14 09:51:37
【问题描述】:
我正在尝试获取 selenium webdriver 中的标题。类似于以下内容:
>>> import requests
>>> res=requests.get('http://google.com')
>>> print res.headers
我需要使用Chrome webdriver,因为它支持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('XY@comcast.net')
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?
我看到了其他一些建议运行整个 selenium 服务器来获取此信息的答案 (https://github.com/derekargueta/selenium-profiler)。我如何通过 Webdriver 使用与上述类似的东西来获得它?
【问题讨论】:
-
您能否详细说明您要提取哪些标头以及用于什么目的?谢谢。
-
很确定你不能开箱即用。