Advertisement
kopyl

Untitled

May 13th, 2021
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1.  
  2. import requests
  3.  
  4.  
  5. p = print
  6.  
  7. macbook_link = "https://ek.ua/APPLE-Z128000DM.htm"
  8.  
  9.  
  10. class Macbook:
  11.  
  12.     def __init__(self, price):
  13.         self.price = self.get_price()
  14.  
  15.     def get_price(self):
  16.         ekua = EkUa()
  17.         self.low_price, self.high_price = ekua.prices
  18.  
  19.  
  20. class EkUa:
  21.  
  22.     def __init__(self):
  23.         self.get_html()
  24.         self.parse()
  25.  
  26.     def parse(self):
  27.         price_location = self.html.index("по цене от")
  28.         price_location = slice(price_location, price_location+100)
  29.         part_with_price = self.html[price_location]
  30.         part_with_price = part_with_price.split()
  31.         low_price, high_price = filter(
  32.             lambda c: c.isnumeric(), part_with_price
  33.         )
  34.         low_price, high_price = int(low_price), int(high_price)
  35.         self.prices = low_price, high_price
  36.  
  37.     def get_html(self):
  38.         self.html = requests.get(macbook_link)
  39.         self.html = self.html.text
  40.  
  41.  
  42. macbook = Macbook(100)
  43. p(macbook.low_price)
  44. p(macbook.high_price)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement