Reputation: 227
I want to capture headers for a specific name from the network traffic. I saw other answers on stackoverflow that talks about using browser mob and all. But what should I do to capture specific header. For example in the image I have uploaded
let's consider the file with Name = id always appears in a link and I want to capture the header (specifically the url) of this file. This
As soon as a file with Name = id appears I should get its Request URL. What should I do for that and also I want to capture the cookie as well.
Any help would me much appreciated. Thank you.
Upvotes: 1
Views: 986
Reputation: 157
Okay if you want to capture the request url of a file and as you said you know the format of the url and you can identify it from many urls then for that you can try this function:
def get_url(args):
network_logs = driver.execute_script("var performance = window.performance || window.mozPerformance || "
"window.msPerformance || window.webkitPerformance || {}; var network = "
"performance.getEntries() || {}; return network;")
for network_log in network_logs:
name = network_log.get("name", "")
if "your_url_identifier" in name:
return name
return False
You can call this method directly after
browser.get(url)
and it will return you the request url which has the string your_url_identifier in it. Something like this:
browser.get(url)
file_link = WebDriverWait(browser, 1000).until(get_url)
This get_url method will keep running until either the desired url is captured or the time (1000 seconds in this example) is over.
Try and let me know if it works.
Upvotes: 1