From 7d4d52144ff971e36c9d71d547156df1b76a45a8 Mon Sep 17 00:00:00 2001 From: Sam Hadow Date: Wed, 27 Dec 2023 18:32:27 +0100 Subject: [PATCH] request test with login token cookies --- main.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..427753c --- /dev/null +++ b/main.py @@ -0,0 +1,40 @@ +import requests, re, json + +def load_cookies_from_file(file_path): + with open(file_path, 'r') as file: + cookies_data = json.load(file) + + cookies_dict = {} + + for cookie_data in cookies_data: + name_raw = cookie_data.get("Name raw", "") + content_raw = cookie_data.get("Content raw", "") + cookie_value = f"{content_raw}" + + if len(cookie_value) > 0: + cookies_dict[name_raw] = cookie_value + + return cookies_dict + + +if __name__ == '__main__': + target_url = 'https://fr.aliexpress.com/item/1005005769229528.html' + + + session = requests.Session() + cookies_file_path = './cookies.json' + cookies = load_cookies_from_file(cookies_file_path) + session.cookies.update(cookies) + url = 'https://fr.aliexpress.com/item/1005005769229528.html' + target_page_response = session.get(url) + + + + if target_page_response.status_code == 200: + regex = re.compile(r'\"skuActivityAmountLocal\":\"[0-9]*,[0-9]{2}') + content = re.findall(regex, target_page_response.text) + print(content) + else: + print(f'Failed to fetch target page. Status code: {target_page_response.status_code}') + +