Created
March 27, 2024 09:41
-
-
Save yamanjain/77fca6dc41938cd54d38331163d0553e to your computer and use it in GitHub Desktop.
Python code to capture outgoing header to be re-used for scraping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some flaw in python code due to which things are intercepted only after clicking twice / two requests | |
def get_intercepted_header(page): | |
global intercepted_header | |
global intercepted_auth_token | |
# URL that is called in the request | |
page.route("**/customeraccounts", handle) | |
# Click the link which sends out a request | |
page.get_by_text("Check Balance").click() | |
# page.route("**/*", handle) | |
def handle(route, request): | |
# override headers | |
print('Intercepted ' + request.url) | |
if 'customeraccounts' in request.url: | |
global intercepted_header | |
global intercepted_auth_token | |
intercepted_auth_token = request.headers['authorization'] | |
intercepted_header = request.headers | |
route.continue_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment