Advertisement
Guest User

erpolska ikea skrypt

a guest
Feb 12th, 2025
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. import requests
  2. import re
  3.  
  4. def fetch_products():
  5.     url = "https://sik.search.blue.cdtapps.com/pl/pl/search?c=listaf&v=20241114"
  6.     headers = {
  7.         "Session-Id": "b7733381-ff70-4451-909f-33751bcf0807",
  8.         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
  9.     }
  10.     payload = {
  11.         "searchParameters": {
  12.             "input": "top_seller",
  13.             "type": "SPECIAL"
  14.         },
  15.         "optimizely": {
  16.             "listing_3086_ratings_and_review_popup": None,
  17.             "sik_null_test_20250205_default": "a"
  18.         },
  19.         "components": [
  20.             {
  21.                 "component": "PRIMARY_AREA",
  22.                 "columns": 4,
  23.                 "types": {
  24.                     "main": "PRODUCT",
  25.                     "breakouts": [
  26.                         "PLANNER",
  27.                         "LOGIN_REMINDER",
  28.                         "MATTRESS_WARRANTY"
  29.                     ]
  30.                 },
  31.                 "window": {
  32.                     "offset": 0,
  33.                     "size": 600
  34.                 }
  35.             }
  36.         ]
  37.     }
  38.     response = requests.post(url, headers=headers, json=payload)
  39.     response.raise_for_status()
  40.     return response.json()
  41.  
  42. def format_product(product):
  43.     product_name = product.get("product", {}).get("name")
  44.     global_id = product.get("product", {}).get("itemNoGlobal")
  45.     filterClass = product.get("product", {}).get("filterClass")
  46.     price_pl = get_single_price("pl/pl",global_id)
  47.     price_de = get_single_price("de/de",global_id)
  48.     return f"{product_name} - {global_id} - {filterClass} - {price_pl} - {price_de}"
  49.  
  50. def get_single_price(region,global_id):
  51.     try:
  52.         url = f"https://www.ikea.com/{region}/p/{global_id}/"
  53.         response = requests.get(url)
  54.         response.raise_for_status()
  55.         pattern = r'"price":\s*\[\s*"(\d+(\.\d{1,2})?)"\s*\]'
  56.         match = re.search(pattern, response.text)
  57.         if match:
  58.             price = match.group(1)
  59.             return price
  60.     except Exception as e:
  61.         print(f"Error fetching price for {global_id}")
  62.         return None
  63.  
  64. def print_products(response):
  65.     for result in response["results"]:
  66.         products = result.get("items", [])
  67.         for product in products:
  68.             print(format_product(product))
  69.  
  70. if __name__ == "__main__":
  71.     products = fetch_products()
  72.     print_products(products)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement