mirror of
https://github.com/kristoferssolo/School.git
synced 2025-10-21 20:10:38 +00:00
Name + price output
This commit is contained in:
parent
7b7d1f43b6
commit
16db763d1b
@ -4,43 +4,40 @@ import requests
|
|||||||
prices = []
|
prices = []
|
||||||
names = []
|
names = []
|
||||||
|
|
||||||
HEADERS = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36 OPR/77.0.4054.275'}
|
HEADERS = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Vivaldi/4.1.2369.21'}
|
||||||
|
|
||||||
|
|
||||||
class IKEA:
|
class IKEA:
|
||||||
def __init__(self, url, price, name):
|
def __init__(self, url, name, price):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.price = price
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.price = price
|
||||||
|
|
||||||
def function(self):
|
def get_data(self):
|
||||||
prices.clear()
|
prices.clear()
|
||||||
url = self.url
|
url = self.url
|
||||||
page = requests.get(url, headers=HEADERS)
|
page = requests.get(url, headers=HEADERS)
|
||||||
soup = BeautifulSoup(page.content, 'html.parser')
|
soup = BeautifulSoup(page.content, 'html.parser')
|
||||||
|
|
||||||
for el in soup.find_all(class_=self.price):
|
|
||||||
cropped_price = el.get_text().strip() # strip necessary info
|
|
||||||
prices.append(cropped_price)
|
|
||||||
|
|
||||||
for el in soup.find_all(class_=self.name):
|
for el in soup.find_all(class_=self.name):
|
||||||
cropped_name = el.get_text().strip()
|
cropped_name = el.get_text().strip()
|
||||||
names.append(cropped_name)
|
names.append(cropped_name)
|
||||||
# converted_price = list(map(convertor, prices)) # converts . to ,
|
|
||||||
# adds € at the end of each element
|
|
||||||
# new_prices = map((lambda x: x + "€"), converted_price)
|
|
||||||
|
|
||||||
# converts list to string
|
for el in soup.find_all(class_=self.price):
|
||||||
# output = f"{self.name}\n" + "\n".join(str(elem) for elem in new_prices)
|
cropped_price = el.get_text().strip()
|
||||||
output = names
|
prices.append(cropped_price[:cropped_price.find("€") + 1])
|
||||||
|
|
||||||
|
combined_list = [i + " - " + j for i, j in zip(names, prices)]
|
||||||
|
output = "\n".join(str(elem) for elem in combined_list)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
aizskari = IKEA('https://www.ikea.lv/lv/products/virtuve/aizkari-un-zaluzijas/aizkari', 'itemBTI display-6', 'display-7 mr-2')
|
curtains = IKEA('https://www.ikea.lv/lv/products/virtuve/aizkari-un-zaluzijas/aizkari', 'display-7 mr-2', 'display-6')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(aizskari.function())
|
print(curtains.get_data())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user