n8henrie / pycookiecheat

Borrow cookies from your browser's authenticated session for use in Python scripts.
https://n8henrie.com/2013/11/use-chromes-cookies-for-easier-downloading-with-python-requests/
MIT License
744 stars 111 forks source link

Add support for Brave cookies. #40

Closed chrisgavin closed 1 year ago

chrisgavin commented 1 year ago

Description

This adds support for fetching cookies from Brave, a relatively popular Chromium-based browser. It works essentially the same as any other Chromium derivative where it uses a different keyring entry and cookie file path, but otherwise uses exactly the same encryption mechanism as Chromium.

Status

READY

Todos

Steps to Test or Reproduce

Install Brave. Generate some cookies. Fetch those cookies.

Python 3.8.10 (default, Nov 14 2022, 12:59:47) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycookiecheat
>>> pycookiecheat.chrome_cookies(url="https://httpbin.org/", browser="Brave")
{'test': 'value'}
n8henrie commented 1 year ago

Interesting, thanks for your PR!

Note to self: I should probably refactor the browser choice into an Enum at some point, and maybe use a match statement once the pre-match pythons are EOL.

I'm also not sure how to test this. Does Brave have a CLI?

chrisgavin commented 1 year ago

Brave itself does not really have a CLI mode, but since it's so close to Chromium it looks like it can be tested in the same way as Chromium is (using Playwright to invoke the browser). I've pushed a commit that updates the tests to allow specifying which browser to run them with, then updated the CI workflow to install Brave and run the tests against it. Maybe this is too heavy-weight to run long term, but hopefully it's at least a reasonable one-off demonstration of it working.

n8henrie commented 1 year ago

Maybe this is too heavy-weight to run long term

I think this is great, since we let GA do the heavy lifting anyway. It lets me verify that it seems to work even though I'm not a Brave user.

Thanks for a solid PR, the attention to detail is appreciated!

n8henrie commented 1 year ago

@chrisgavin I've merged this and a few other commits into dev. Can you please install the dev branch and verify things still work? If so I'll cut a new release on PyPI.

$ python -m pip install git+https://github.com/n8henrie/pycookiecheat@dev
chrisgavin commented 1 year ago

Hi @n8henrie. Happy to confirm things are working great with the dev branch for me. Thank you very much for merging my PR! :heart: