Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python script to extract headers quickly #59

Open
av1d opened this issue Jul 25, 2024 · 0 comments
Open

Python script to extract headers quickly #59

av1d opened this issue Jul 25, 2024 · 0 comments

Comments

@av1d
Copy link

av1d commented Jul 25, 2024

I've made a fast way to obtain the credentials.

To use this, you want to load Twitter/X, open the DevTools by pressing CTRL + SHIFT + I, filter by Fetch/XHR, refresh the page.
Right-click something, click "Copy", then "copy all as cURL".
Run the python script python extract.py or whatever, then paste what you copied into it. Press enter twice.

import re

def extract_headers(curl_command):
    # headers you want to extract
    headers_to_extract = [
        'authorization',
        'x-client-uuid',
        'x-client-transaction-id'
    ]
    
    # regex pattern to match the headers
    pattern = re.compile(r"-H '([^:]+): ([^']+)'")
    
    extracted_headers = {}

    # find all headers
    for match in pattern.finditer(curl_command):
        header_name = match.group(1).strip().lower()
        header_value = match.group(2).strip()

        if header_name in headers_to_extract:
            extracted_headers[header_name] = header_value

    return extracted_headers

def main():

    print("Paste your curl command below (end with an empty line):")
    curl_command = []
    
    while True:
        line = input()
        if line.strip() == "":
            break
        curl_command.append(line)
    
    curl_command_str = "\n".join(curl_command)

    # extract headers
    headers = extract_headers(curl_command_str)

    # print result
    for key, value in headers.items():
        print(f"-H '{key}: {value}'")

if __name__ == "__main__":
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant