If you work with strings in your Python scripts and you're writing obscure logic to process them, then you need to look into regex in Python. It lets you describe patterns instead of writing ...
Smarter document extraction starts here.
The parseString function takes a string representing a single cookie and an optional configuration object of type ParseStringOptions. It returns an object representing the parsed cookie.