From 47418c464c186b4abe3b0ccdbab8526c9b684bf0 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 10 Nov 2020 20:14:33 -0800 Subject: [PATCH] Use requests.Session. --- getcrx.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/getcrx.py b/getcrx.py index f436453..b279ab8 100644 --- a/getcrx.py +++ b/getcrx.py @@ -16,6 +16,8 @@ FILENAME_BADCHARS = '\\/:*?<>|"' WEBSTORE_URL = 'https://chrome.google.com/webstore/detail/x/{extension_id}' CRX_URL = 'https://clients2.google.com/service/update2/crx?response=redirect&prodversion=83.0.4103.116&acceptformat=crx2,crx3&x=id%3D{extension_id}%26uc' +session = requests.Session() + def sanitize_filename(name): for c in FILENAME_BADCHARS: name = name.replace(c, '-') @@ -23,7 +25,7 @@ def sanitize_filename(name): def get_webstore_name_version(extension_id): url = WEBSTORE_URL.format(extension_id=extension_id) - response = requests.get(url) + response = session.get(url) try: name = response.text name = name.split('meta property="og:title" content="')[1] @@ -50,7 +52,7 @@ def get_crx_name_version(crx_bytes): def getcrx(extension_id, auto_overwrite=None): url = CRX_URL.format(extension_id=extension_id) - response = requests.get(url) + response = session.get(url) response.raise_for_status() (name, version) = get_webstore_name_version(extension_id)