44 lines
2.0 KiB
Python
44 lines
2.0 KiB
Python
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__':
|
|
|
|
|
|
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'
|
|
|
|
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.search(item_regex, target_page_response.text).group(12)
|
|
print(content)
|
|
else:
|
|
print(f'Failed to fetch target page. Status code: {target_page_response.status_code}')
|
|
|
|
|