Capturing traffic in Selenium Capturing traffic in Selenium selenium selenium

Capturing traffic in Selenium


You can't get the request or response body with Selenium - it only captures headers. Try Fiddler2 if you're running on Windows.


When selenium gives you the request headers, they have the information to craft a PyCurl or urllib request that fetches the response bodies.

For me this was as easy as running the following regex to rip out the urls, and then using curl to fetch them.

urls = re.finditer('\n  "url":"(.*)",', sel.captureNetworkTraffic('json'))

a regex was used since some of the responses had embedded json causing json.loads to blow up :(. There is some additional effort if the parameters are all in the response header instead of the url.


Note: I may need more information about what you are trying to accomplish and why you chose selenium.

The only thing I can think of is piping the output of tshark or something similar into your python program. I suppose there are also pcap readers, but I have no experience with these. I briefly searched for a python network monitoring api, but had no such luck.