How to grab headers in python selenium-webdriver
<p>I am trying to grab the headers in selenium webdriver. Something similar to the following:</p>

<pre><code>&gt;&gt;&gt; import requests
&gt;&gt;&gt; res=requests.get('http://google.com')
&gt;&gt;&gt; print res.headers
</code></pre>

<p>I need to use the <code>Chrome</code> webdriver because it supports flash and some other things that I need to test a web page. Here is what I have so far in Selenium:</p>

<pre><code>from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://login.comcast.net/login?r=comcast.net&amp;s=oauth&amp;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&amp;reqId=18737431-624b-44cb-adf0-2a85d91bd662&amp;forceAuthn=1&amp;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?
</code></pre>

<p>I have seen some other answers that recommend running an entire selenium server to get this information (<a href="https://github.com/derekargueta/selenium-profiler" rel="nofollow">https://github.com/derekargueta/selenium-profiler</a>). How would I get it using something similar to the above with Webdriver?</p>

<p>Unfortunately, you <strong>cannot</strong> get this information from the Selenium webdriver, nor will you be able to any time in the near future it seems. An excerpt from <a href="https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/141" rel="nofollow">a very long conversation on the subject</a>:</p>

<blockquote>
  <p>This feature isn't going to happen.</p>
</blockquote>

<p>The gist of the main reason being, from what I gather from the discussion, that the webdriver is meant for "driving the browser", and extending the API beyond that primary goal will, in the opinion of the developers, cause the overall quality and reliability of the API to suffer. </p>

<p>One potential workaround that I have seen suggested in a number of places, including the conversation linked above, is to use <a href="https://github.com/lightbody/browsermob-proxy" rel="nofollow">BrowserMob Proxy</a>, which can be used to capture HTTP content, and <a href="https://github.com/lightbody/browsermob-proxy#using-with-selenium" rel="nofollow">can be used with selenium</a> - though the linked example does not use the Python selenium API. It does seem that there is <a href="https://github.com/AutomatedTester/browsermob-proxy-py" rel="nofollow">a Python wrapper for BrowserMob Proxy</a>, but I cannot vouch for it's efficacy since I have never used it. </p>

python selenium