pythonselenium-webdriverhttp-headers

How to fetch status of javascript and css requests from network in selenium python


I want to fetch the status of specific JavaScript and CSS network requests of my website https://lifesciences.cactusglobal.com. These network requests can be seen in chrome network. I want to print the request URL and its response code. Screenshot attached below for reference, check the underlined requests:

enter image description here

I tried using the package selenium-wire

driver.get('https://www.google.com')

for request in driver.requests:
    if request.response:
        print(
            request.url,
            request.response.status_code,
            request.response.headers['Content-Type']
        )

But it returns only responses and headers of the URL entered and not the network requests. Is there any other way to traverse through the network requests in selenium python?

Thanks


Solution

  • Many thanks for your support. I found a solution which suits my requirement well.
    Referred to these links:
    https://gist.github.com/rengler33/f8b9d3f26a518c08a414f6f86109863c https://www.rkengler.com/how-to-capture-network-traffic-when-scraping-with-selenium-and-python/
    Also found a package as an easy way out (not sticking to it though) - pip install selenium-wire