-
Notifications
You must be signed in to change notification settings - Fork 0
/
koton-products.py
49 lines (29 loc) · 1.07 KB
/
koton-products.py
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
from urllib.request import urlopen as uReq
import csv
from bs4 import BeautifulSoup as soup
import pandas as pd
page_url = "https://www.trendyol.com/koton---kadin--erkek-tekstil/butikdetay/323498"
uClient = uReq(page_url)
page_soup = soup(uClient.read(),"html.parser")
uClient.close()
containers = page_soup.findAll("div",{"class":"product"})
out_filename = "koton_products.csv"
headers = "Product-Name,Product-Sale-Rate,Product-Price\n"
#open file and wrtie headers
f = open(out_filename,"w")
f.write(headers)
names = []
sales = []
price = []
i = 0
for container in containers:
names.append(container.findAll("div",{"class":"name"})[0].text)
sales.append(container.findAll("div",{"class":"promotion-text"})[0].text)
price.append(container.findAll("div",{"class":"discounted-price"})[0].text)
print("Product Name: ",names[i][:-12])
print("Product Sale Rate:",sales[i])
print("Product Price:",price[i])
print("-"*40)
f.write(names[i] + "," + sales[i] + "," + price[i] + "\n")
i +=1
f.close()