diff --git a/.gitignore b/.gitignore index 02932dce..b4be74b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .venv -.codegpt \ No newline at end of file +.codegpt +__pycache__ \ No newline at end of file diff --git a/parser/currency.py b/parser/currency.py index 01354f96..3036404a 100644 --- a/parser/currency.py +++ b/parser/currency.py @@ -1,20 +1,17 @@ import requests -import json url = "https://www.cbr-xml-daily.ru/daily_json.js" + class Currency: def __init__(self, code: str): self.name = code self.status = True response = requests.get(url) - response.raise_for_status() # Проверяем успешность запроса + response.raise_for_status() try: - # Парсим JSON-данные data = response.json() - self.yen_rate = data["Valute"][code]["Value"] - self.yen_nominal = data["Valute"][code]["Nominal"] - except: + self.rate = data["Valute"][code]["Value"] + self.nominal = data["Valute"][code]["Nominal"] + except Exception: self.status = False - -obj = Currency("JPY") \ No newline at end of file diff --git a/parser/item.py b/parser/item.py new file mode 100644 index 00000000..e61b3c9a --- /dev/null +++ b/parser/item.py @@ -0,0 +1,6 @@ +class Item: + def __init__(self, name: str, category: str, price: float, photo_url: str): + self.name = name + self.category = category + self.price = price + self.photo_url = photo_url diff --git a/parser/main.py b/parser/main.py index 0892ad4f..a83e9e1c 100644 --- a/parser/main.py +++ b/parser/main.py @@ -1,17 +1,46 @@ -from currency import Currency +import sys + import requests from bs4 import BeautifulSoup +from currency import Currency +from item import Item -url = "https://irose-shop.net/?category_id=52b1abaf8a56103f0500013e" +items = [] + +bank = Currency("JPY") +if not bank.status: + print("Not correct currency code") + sys.exit() + +url = "https://www.fint-shop.com/c/all/bag?top_category" response = requests.get(url) response.raise_for_status() soup = BeautifulSoup(response.text, "html.parser") -products = soup.find_all("div", class_="c-itemList__item") -print(products) -# bank = Currency("JPY") -# price = 19160 +products = soup.find_all("article", class_="fs-c-productList__list__item") +category_name = soup.find_all("li", class_="fs-c-breadcrumb__listItem")[1].get_text( + strip=True +) +print(category_name) +for product in products: + product_name = product.find("span", class_="fs-c-productName__name").get_text( + strip=True + ) -# print(f"Price in Russian Rubles: {price * ((bank.yen_rate/bank.yen_nominal))}") \ No newline at end of file + price = int( + product.find("div", class_="fs-c-productPrice--listed") + .find("span", class_="fs-c-price__value") + .get_text(strip=True) + .replace(",", "") + ) + product_price = round(price * (bank.rate / bank.nominal), 2) + + product_photo = product.find( + "img", class_="fs-c-productListItem__image__image fs-c-productImage__image" + )["data-layzr"] + items.append(Item(product_name, "bags", product_price, product_photo)) + +for item in items: + print(f"Name = {item.name}, price = {item.price}")