Seleniumbase: Intercept HTTP requests

140 Views Asked by At

With Selenium Wire, you can intercept your requests like this:

from seleniumwire import webdriver 

def intercept_response(request, response):
        print(request.headers)
    
driver = webdriver.Chrome()
driver.response_interceptor = intercept_response

This prints a continuous stream of data for every request you make.

I attempted to do the same thing with SeleniumBase, but it doesn't work. The following only prints a single GET request, but the linkedIn page that I am visiting should yield multiple GET requests.

from seleniumbase import Driver
driver = Driver(browser="chrome", pls="eager", agent=agent, proxy=proxy, headed=True, wire=True)

driver.get("https://www.linkedin.com")
for request in driver.requests:
    print(request.url)
1

There are 1 best solutions below

2
Michael Mintz On

If this is the selenium-wire version:

from seleniumwire import webdriver

def intercept_response(request, response):
    print(request.headers)

driver = webdriver.Chrome()
driver.response_interceptor = intercept_response
driver.get("https://wikipedia.org")
driver.quit()

Then the SeleniumBase equivalent would be:

from seleniumbase import Driver

def intercept_response(request, response):
    print(request.headers)

driver = Driver(wire=True)
driver.response_interceptor = intercept_response
driver.get("https://wikipedia.org")
driver.quit()