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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

atuo fetch cookie from chrome #763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion coursera/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ def parse_args(args=None):
default=None,
help='full path to the cookies.txt file')

group_adv_auth.add_argument(
'-acc',
'--autocookie_chrome',
action='store_true',
default=False,
help='auto load chrome cookie')

group_adv_auth.add_argument(
'-n',
'--netrc',
Expand Down Expand Up @@ -500,7 +507,7 @@ def parse_args(args=None):
logging.error('Cookies file not found: %s', args.cookies_file)
sys.exit(1)

if not args.cookies_file and not args.cookies_cauth:
if not args.cookies_file and not args.cookies_cauth and not args.autocookie_chrome:
try:
args.username, args.password = get_credentials(
username=args.username, password=args.password,
Expand Down
10 changes: 10 additions & 0 deletions coursera/coursera_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ def main():
session = get_session()
if args.cookies_cauth:
session.cookies.set('CAUTH', args.cookies_cauth)
elif args.autocookie_chrome:
def autocookie():
import browser_cookie3
cj = browser_cookie3.chrome(domain_name='coursera.org')
for cookie in cj:
if cookie.name =='CAUTH':
return cookie.value
else:
raise Exception("can not find CAUTH in Chrome.")
session.cookies.set('CAUTH', autocookie())
else:
login(session, args.username, args.password)
if args.specialization:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pyasn1>=0.1.7
keyring>=4.0
configargparse>=0.12.0
attrs==18.1.0
browser_cookie3==0.7.6