-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (50 loc) · 1.9 KB
/
main.py
File metadata and controls
58 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from bs4 import BeautifulSoup
import requests
import pandas as pd
import numpy as np
from abc import ABC, abstractmethod
class ProductPrice:
"""Abstract Factory Interface"""
@abstractmethod
def get_product_price(self, url):
pass
class TrendyolProductPrice(ProductPrice):
def get_product_price(self, url) -> None:
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
product_info_container = soup.find('div', class_='product-price-container')
price_element = product_info_container.find_all('span', class_='prc-dsc')
if price_element:
print(price_element[0].text)
return
else:
return 'Fiyat bilgisi bulunamadı.'
class TeknosaProductPrice(ProductPrice):
def get_product_price(self, url) -> None:
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
product_info_container = soup.find('div', class_='pdp-prices')
price_element = product_info_container.find_all('span', class_='prc')
if price_element:
print(price_element[0].text)
return
else:
return 'Fiyat bilgisi bulunamadı.'
class ProductPriceFactory(ABC):
@abstractmethod
def create_product_price(self) -> ProductPrice:
pass
class ConcreteProductPriceFactory(ProductPriceFactory):
def create_product_price(self, type: str) -> ProductPrice:
match type:
case "trendyol":
return TrendyolProductPrice()
case "teknosa":
return TeknosaProductPrice()
case _:
raise ValueError("Bir şeyler ters gitti")
if __name__ == "__main__":
factory = ConcreteProductPriceFactory()
url = input("Ürün linki girin \n")
company = url.split('.')[1]
price = factory.create_product_price(company).get_product_price(url)