Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- p = print
- macbook_link = "https://ek.ua/APPLE-Z128000DM.htm"
- class Macbook:
- def __init__(self, price):
- self.price = self.get_price()
- def get_price(self):
- ekua = EkUa()
- self.low_price, self.high_price = ekua.prices
- class EkUa:
- def __init__(self):
- self.get_html()
- self.parse()
- def parse(self):
- price_location = self.html.index("по цене от")
- price_location = slice(price_location, price_location+100)
- part_with_price = self.html[price_location]
- part_with_price = part_with_price.split()
- low_price, high_price = filter(
- lambda c: c.isnumeric(), part_with_price
- )
- low_price, high_price = int(low_price), int(high_price)
- self.prices = low_price, high_price
- def get_html(self):
- self.html = requests.get(macbook_link)
- self.html = self.html.text
- macbook = Macbook(100)
- p(macbook.low_price)
- p(macbook.high_price)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement