Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import re
- def fetch_products():
- url = "https://sik.search.blue.cdtapps.com/pl/pl/search?c=listaf&v=20241114"
- headers = {
- "Session-Id": "b7733381-ff70-4451-909f-33751bcf0807",
- "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"
- }
- payload = {
- "searchParameters": {
- "input": "top_seller",
- "type": "SPECIAL"
- },
- "optimizely": {
- "listing_3086_ratings_and_review_popup": None,
- "sik_null_test_20250205_default": "a"
- },
- "components": [
- {
- "component": "PRIMARY_AREA",
- "columns": 4,
- "types": {
- "main": "PRODUCT",
- "breakouts": [
- "PLANNER",
- "LOGIN_REMINDER",
- "MATTRESS_WARRANTY"
- ]
- },
- "window": {
- "offset": 0,
- "size": 600
- }
- }
- ]
- }
- response = requests.post(url, headers=headers, json=payload)
- response.raise_for_status()
- return response.json()
- def format_product(product):
- product_name = product.get("product", {}).get("name")
- global_id = product.get("product", {}).get("itemNoGlobal")
- filterClass = product.get("product", {}).get("filterClass")
- price_pl = get_single_price("pl/pl",global_id)
- price_de = get_single_price("de/de",global_id)
- return f"{product_name} - {global_id} - {filterClass} - {price_pl} - {price_de}"
- def get_single_price(region,global_id):
- try:
- url = f"https://www.ikea.com/{region}/p/{global_id}/"
- response = requests.get(url)
- response.raise_for_status()
- pattern = r'"price":\s*\[\s*"(\d+(\.\d{1,2})?)"\s*\]'
- match = re.search(pattern, response.text)
- if match:
- price = match.group(1)
- return price
- except Exception as e:
- print(f"Error fetching price for {global_id}")
- return None
- def print_products(response):
- for result in response["results"]:
- products = result.get("items", [])
- for product in products:
- print(format_product(product))
- if __name__ == "__main__":
- products = fetch_products()
- print_products(products)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement