Skip to main content Scroll Top

Программа Парсер Цен Api ⭐ Full Version

# Проверяем базу данных price = await db.fetch_one("SELECT * FROM prices WHERE product_id=$1 ORDER BY timestamp DESC LIMIT 1", product_id) if not price: raise HTTPException(status_code=404, detail="Product not found")

# Псевдокод для Scrapy def parse_price(self, response): # 1. Пробуем найти JSON-LD (схема Schema.org) json_data = response.xpath('//script[@type="application/ld+json"]/text()').get() if json_data: price = extract_price_from_json(json_data) # 2. Ищем стандартные CSS-классы if not price: price = response.css('.price-current__number::text').get() программа парсер цен api

Пользовательский запрос -> API (проверка кэша) -> [если данных нет] -> Очередь задач -> Воркер -> Сайт -> База данных -> API -> Ответ Языки и библиотеки | Язык | Библиотеки | Плюсы для парсинга цен | |------|------------|------------------------| | Python | BeautifulSoup4, Scrapy, Selenium, Playwright | Огромная экосистема, быстрая разработка | | Node.js | Puppeteer, Cheerio, Axios | Отличная работа с асинхронностью, нативная работа с JSON | | Go | Colly, chromedp | Высокая производительность, низкое потребление памяти | # Проверяем базу данных price = await db

@app.get("/price/product_id") async def get_price(product_id: str): # Сначала проверяем кэш (TTL 5 минут) cached = cache.get(f"price:product_id") if cached: return json.loads(cached) заменяем запятую Предположим

# 3. Fallback: регулярное выражение на сумму if not price: price = re.search(r'[\d\s]+[.,]?\d2₽', response.text)

return normalize_price(price) # убираем пробелы, заменяем запятую Предположим, мы используем FastAPI (Python) для простоты и производительности. Модели данных from pydantic import BaseModel from datetime import datetime class PriceRecord(BaseModel): product_id: str source_url: str price: float currency: str = "RUB" timestamp: datetime in_stock: bool Эндпоинты | Метод | URL | Описание | |-------|-----|----------| | GET | /api/v1/prices/product_id | Получить последнюю цену | | GET | /api/v1/prices/history/product_id?from=date&to=date | Исторические цены | | POST | /api/v1/parse/request | Запросить принудительный парсинг сейчас | | GET | /api/v1/products/search?query=...&min_price=... | Поиск товаров с фильтрацией по цене | Пример реализации (FastAPI) from fastapi import FastAPI, BackgroundTasks, HTTPException from redis import Redis import json app = FastAPI() cache = Redis()

программа парсер цен api

You're almost there! Just a few contact details, and you'll get deep digital insights straight to your inbox.

* indicates required





You can unsubscribe at any time by clicking the link in the footer of our emails.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.


программа парсер цен api

You're almost there! Just a few contact details, and you'll get deep digital insights straight to your inbox.

* indicates required





You can unsubscribe at any time by clicking the link in the footer of our emails.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.