forked from harshitroy2605/webscrapping-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.py
130 lines (115 loc) · 4.21 KB
/
1.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
from tkinter import *
import requests
from bs4 import BeautifulSoup
import pandas
window=Tk()
def view_command():
if item_listbox.get()=="lamps":
listbox1.delete('0','end')
r=requests.get("https://www.thehutcafe.com/products?category=the-hut-cafe-lamp-collection")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("div",{"class":"small-6 medium-4 large-3 xlarge-3 columns product-column"})
l=[]
r=0
for item in all:
d={}
d["name"]=item.find("h2").text+""
d["price"]=item.find("",{"class":"product-copy-price-current"}).text.replace("₹","").replace(" ","")
l.append(d)
listbox1.insert(END,l[r]['name']+"₹"+l[r]['price'])
r=r+1
elif item_listbox.get()=="chandlier":
listbox1.delete('0','end')
r=requests.get("https://www.thehutcafe.com/products?category=peacock-chandeliers")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("div",{"class":"small-6 medium-4 large-3 xlarge-3 columns product-column"})
l=[]
r=0
for item in all:
d={}
d["name"]=item.find("h2").text+""
d["price"]=item.find("",{"class":"product-copy-price-current"}).text.replace("₹","").replace(" ","")
l.append(d)
listbox1.insert(END,l[r]['name']+"₹"+l[r]['price'])
r=r+1
elif item_listbox.get()=="ships":
listbox1.delete('0','end')
r=requests.get("https://www.thehutcafe.com/products?category=ship-models")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("div",{"class":"small-6 medium-4 large-3 xlarge-3 columns product-column"})
l=[]
r=0
for item in all:
d={}
d["name"]=item.find("h2").text+""
d["price"]=item.find("",{"class":"product-copy-price-current"}).text.replace("₹","").replace(" ","")
l.append(d)
listbox1.insert(END,l[r]['name']+"₹"+l[r]['price'])
r=r+1
elif item_listbox.get()=="coffee table":
listbox1.delete('0','end')
r=requests.get("https://www.thehutcafe.com/products?category=ornate-coffee-table")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("div",{"class":"small-6 medium-4 large-3 xlarge-3 columns product-column"})
l=[]
r=0
for item in all:
d={}
d["name"]=item.find("h2").text+""
d["price"]=item.find("",{"class":"product-copy-price-current"}).text.replace("₹","").replace(" ","")
l.append(d)
listbox1.insert(END,l[r]['name']+"₹"+l[r]['price'])
r=r+1
elif item_listbox.get()=="animal lamps":
listbox1.delete('0','end')
r=requests.get("https://www.thehutcafe.com/products?category=coco-animal-lamps-1")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("div",{"class":"small-6 medium-4 large-3 xlarge-3 columns product-column"})
l=[]
r=0
for item in all:
d={}
d["name"]=item.find("h2").text+""
d["price"]=item.find("",{"class":"product-copy-price-current"}).text.replace("₹","").replace(" ","")
l.append(d)
listbox1.insert(END,l[r]['name']+"₹"+l[r]['price'])
r=r+1
elif item_listbox.get()=="all products":
listbox1.delete('0','end')
r=requests.get("https://www.thehutcafe.com/products")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all=soup.find_all("div",{"class":"small-6 medium-4 large-3 xlarge-3 columns product-column"})
l=[]
r=0
for item in all:
d={}
d["name"]=item.find("h2").text+""
d["price"]=item.find("",{"class":"product-copy-price-current"}).text.replace("₹","").replace(" ","")
l.append(d)
listbox1.insert(END,l[r]['name']+"₹"+l[r]['price'])
r=r+1
window.geometry("550x400")
label1=Label(window,text="The hutcafe",font="times 24 bold")
label1.grid(row=0,column=4)
label2=Label(window,text="select the option",font="times 14 italic")
label2.grid(row=3,column=4)
items_list=["lamps","chandlier","ships","coffee table","animal lamps","all products"]
item_listbox=StringVar(window)
item_listbox.set("select product")
menu=OptionMenu(window,item_listbox,*items_list)
menu.grid(row=5,column=4)
listbox1=Listbox(window,height=15,width=80)
listbox1.grid(row=10,column=3,rowspan=6,columnspan=3,pady=10,padx=20)
sb1=Scrollbar(window)
sb1.grid(row=10,column=6,sticky='ns',rowspan=6)
listbox1.configure(yscrollcommand=sb1.set)
sb1.configure(command=listbox1.yview)
b1=Button(window,text="Search",command=view_command,width=12,bg='gray')
b1.grid(row=7,column=4)
window.mainloop()