Skip to content

Instantly share code, notes, and snippets.

@h3ssan
Created June 27, 2022 22:44
Show Gist options
  • Save h3ssan/28196d1b4361b96b9358e844e5bb5cf0 to your computer and use it in GitHub Desktop.
Save h3ssan/28196d1b4361b96b9358e844e5bb5cf0 to your computer and use it in GitHub Desktop.
Convert netscape cookies to use in python 3 requests library
import re

def parseCookieFile() -> dict:
    ''' parseCookieFile function used to convert
        NetScape cookies file into a dictionary '''
        
    cookies = {}
    with open (COOKIES_FILE, 'r') as file:
        for line in file:
            if not re.match(r'^\#', line):
                lineFields = line.strip().split('\t')
                cookies[lineFields[5]] = lineFields[6]
    
    return cookies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment