Example of fint-shop's parsing
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
.venv
|
||||
.codegpt
|
||||
__pycache__
|
||||
@@ -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")
|
||||
6
parser/item.py
Normal file
6
parser/item.py
Normal file
@@ -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
|
||||
@@ -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))}")
|
||||
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}")
|
||||
|
||||
Reference in New Issue
Block a user