Example of fint-shop's parsing
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
.venv
|
.venv
|
||||||
.codegpt
|
.codegpt
|
||||||
|
__pycache__
|
||||||
@@ -1,20 +1,17 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
|
||||||
|
|
||||||
url = "https://www.cbr-xml-daily.ru/daily_json.js"
|
url = "https://www.cbr-xml-daily.ru/daily_json.js"
|
||||||
|
|
||||||
|
|
||||||
class Currency:
|
class Currency:
|
||||||
def __init__(self, code: str):
|
def __init__(self, code: str):
|
||||||
self.name = code
|
self.name = code
|
||||||
self.status = True
|
self.status = True
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
response.raise_for_status() # Проверяем успешность запроса
|
response.raise_for_status()
|
||||||
try:
|
try:
|
||||||
# Парсим JSON-данные
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
self.yen_rate = data["Valute"][code]["Value"]
|
self.rate = data["Valute"][code]["Value"]
|
||||||
self.yen_nominal = data["Valute"][code]["Nominal"]
|
self.nominal = data["Valute"][code]["Nominal"]
|
||||||
except:
|
except Exception:
|
||||||
self.status = False
|
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
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
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 = requests.get(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
|
||||||
soup = BeautifulSoup(response.text, "html.parser")
|
soup = BeautifulSoup(response.text, "html.parser")
|
||||||
|
|
||||||
products = soup.find_all("div", class_="c-itemList__item")
|
products = soup.find_all("article", class_="fs-c-productList__list__item")
|
||||||
print(products)
|
category_name = soup.find_all("li", class_="fs-c-breadcrumb__listItem")[1].get_text(
|
||||||
# bank = Currency("JPY")
|
strip=True
|
||||||
# price = 19160
|
)
|
||||||
|
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