-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_v0.py
122 lines (117 loc) · 2.89 KB
/
setup_v0.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
import requests,sys
from bs4 import BeautifulSoup
from tkinter import *
def site_code(url):
page=requests.get(url)
if page.status_code !=200:
print("error response with site you can't continue")
sys.exit()
else :
print("response good you can continue\n")
return page.content
def info_site(source_code):
bs=BeautifulSoup(source_code,"html.parser")
dta=[]
ii=[]
try :
a=bs.html.body
#print(a.prettify)
except:
print("you cant access nav")
contain=a.select(".wrapper")
contain=contain[0]
#print(contain)
for i in contain.children:
dta.append(i)
#print(dta)
#print("len data is >: "+str(len(dta)))
"""
#test dta
for i in range(0,len(dta)):
if dta[i].name!=None:
print("index is >:"+str(i)+" must not none>:"+str(dta[i].name))
else:
print("index is "+str(i)+" must none>:"+str(dta[i].name))
print(dta[i].encode("UTF8"))
"""
n=0
m=0
while n==0:
if dta[m].name!=None:
if m==len(dta)-1:
n=1
break
#print(dta[m].name)
m=m+1
else :
#print("delet>:"+str(dta[m].name),end=" ")
del dta[m]
#print("deleted")
m=0
n=0
#print("len data is >: "+str(len(dta)))
#print(dta)
for i in dta:
if i.name=="div" and i["class"]==["container","test-site"]:
s=i
dta=[]
for i in s.children:
dta.append(i)
for i in dta:
if i.name=="div" and i["class"]==["row"]:
s=i
dta=[]
for i in s.children:
dta.append(i)
for i in dta:
if i.name=="div" and i["class"]==["col-md-9"]:
s=i
dta=[]
for i in s.children:
dta.append(i)
for i in dta:
if i.name=="div" and i["class"]==["row"]:
s=i
dta=[]
dta_a=[]
for i in s.children:
dta.append(i)
hh=1
for i in dta:
if i.name=="div" and i["class"]==["col-sm-4","col-lg-4","col-md-4"]:
s=i.div
print("product "+str(hh)+">:")
hh=hh+1
for j in s.children:
if j.name=="img":
src="https://webscraper.io/test-sites/e-commerce/allinone/"+j["src"]
print("\t",end="")
print("pic>:"+str(src))
if j.name=="div" and j["class"]==["caption"]:
for h in j.children:
if h.name!=None:
dta_a.append(h)
for k in dta_a:
try :
if k.name=="h4" and k["class"]==["pull-right","price"]:
pass
except:
k["class"]=["name"]
if k.name=="h4" and k["class"]==["name"]:
name_p=k.a.string
link_p="https://webscraper.io/test-sites/e-commerce/allinone/"+str(k.a["href"])
print("\t",end="")
print("name product is >:"+str(name_p))
print("\t",end="")
print("link is>:"+str(link_p))
if k.name=="h4" and k["class"]==["pull-right","price"]:
price_p=k.string
print("\t",end="")
print("price of product >:"+str(price_p))
if k.name=="p" and k["class"]==["description"]:
desc_p=k.string
print("\t",end="")
print("desc this product>:"+str(desc_p))
dta_a=[]
source=site_code("https://webscraper.io/test-sites/e-commerce/allinone")
info_site(source)