Skip to content

Instantly share code, notes, and snippets.

@yamanjain
Created March 27, 2024 09:41
Show Gist options
  • Save yamanjain/77fca6dc41938cd54d38331163d0553e to your computer and use it in GitHub Desktop.
Save yamanjain/77fca6dc41938cd54d38331163d0553e to your computer and use it in GitHub Desktop.
Python code to capture outgoing header to be re-used for scraping
# 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