Reputation: 181
I am using a simple html file that references a javascript file which internally makes a call to an https endpoint. And I need to intercept the request and response on the specific url programatically. I cannot invoke the URL directly. Usually, I would use a browser to load the html file and reference the network tab in the developer tools to intercept the call to the specific URL and that is manual. I need to mimic the same programatically.
I tried using the following -
from seleniumwire import webdriver # Import from seleniumwire
# Create a new instance of the Chrome driver
driver = webdriver.Chrome()
# Go to the Google home page
driver.get('file:///Users/myfolder/mypocfolder/mysimulator.html?param1=abcdefg')
# driver.get('https://example.com/xyz'); (This url gets called on loading the above url)
# Access requests via the `requests` attribute
print(len(driver.requests))
for request in driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type']
)
The above does not work for me. What other options can I try other than selenium? I am expecting the https://example.com/xyz will be called on loading my html (it happens in the browser).
Thank you
Upvotes: 0
Views: 1052