|
import browser_cookie3 |
|
|
|
|
|
class Utils: |
|
browsers = [ |
|
browser_cookie3.chrome, |
|
browser_cookie3.safari, |
|
browser_cookie3.firefox, |
|
browser_cookie3.edge, |
|
browser_cookie3.opera, |
|
browser_cookie3.brave, |
|
browser_cookie3.opera_gx, |
|
browser_cookie3.vivaldi, |
|
] |
|
|
|
def get_cookies(domain: str, setName: str = None, setBrowser: str = False) -> dict: |
|
cookies = {} |
|
|
|
if setBrowser != False: |
|
for browser in Utils.browsers: |
|
if browser.__name__ == setBrowser: |
|
try: |
|
for c in browser(domain_name=domain): |
|
if c.name not in cookies: |
|
cookies = cookies | {c.name: c.value} |
|
|
|
except Exception as e: |
|
pass |
|
|
|
else: |
|
for browser in Utils.browsers: |
|
try: |
|
for c in browser(domain_name=domain): |
|
if c.name not in cookies: |
|
cookies = cookies | {c.name: c.value} |
|
|
|
except Exception as e: |
|
pass |
|
|
|
if setName: |
|
try: |
|
return {setName: cookies[setName]} |
|
|
|
except ValueError: |
|
print(f'Error: could not find {setName} cookie in any browser.') |
|
exit(1) |
|
|
|
else: |
|
return cookies |
|
|