44 lines
2.0 KiB
Python
Raw Normal View History

2023-12-27 18:32:27 +01:00
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__':
2023-12-27 21:52:57 +01:00
item_regex = re.compile(r'skuAttr\\\":\\\"(([0-9]*:[0-9]*#[a-zA-Z0-9 ]*;?)*)\\\",\\\"skuId\\\":([0-9]*),\\\"skuIdStr\\\":\\\"[0-9]*\\\",\\\"skuPropIds\\\":\\\"[0-9,]*\\\",\\\"skuVal\\\":{\\\"availQuantity\\\":([0-9]*),(\\\"discount\\\":\\\"([0-9]*)\\\",\\\"discountTips\\\":\\\"-[0-9]*%\\\",)?\\\"hideOriPrice\\\":(false|true),\\\"inventory\\\":([0-9]*),\\\"isActivity\\\":(true|false),\\\"optionalWarrantyPrice\\\":\[\],(\\\"skuActivityAmount\\\":{\\\"currency\\\":\\\"([A-Z]*)\\\",\\\"formatedAmount\\\":\\\"[0-9]*,[0-9]*.\\\",\\\"value\\\":([0-9]*\.[0-9]*)},\\\"skuActivityAmountLocal\\\":\\\"[0-9]*,[0-9]*.\|[0-9]*\|[0-9]*\\\",)?\\\"skuAmount\\\":{\\\"currency\\\":\\\"([A-Z]*)\\\",\\\"formatedAmount\\\":\\\"[0-9]*,[0-9]*.\\\",\\\"value\\\":([0-9]*\.[0-9]*)}')
choice_regex = re.compile(r'businessModel\\\":\\\"(UN_CHOICE|CHOICE)\\\"')
#shipping_cost_regex = re.compile(r'')
target_url = 'https://fr.aliexpress.com/item/1005005769229528.html'
2023-12-27 18:32:27 +01:00
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:
2023-12-27 21:52:57 +01:00
#regex = re.compile(r'\"skuActivityAmountLocal\":\"[0-9]*,[0-9]{2}')
content = re.search(item_regex, target_page_response.text).group(12)
2023-12-27 18:32:27 +01:00
print(content)
else:
print(f'Failed to fetch target page. Status code: {target_page_response.status_code}')