-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamsung-galaxy-a7.py
83 lines (61 loc) · 1.78 KB
/
samsung-galaxy-a7.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
import urllib.request as ur
import re
url = ['http://www.mysmartprice.com/mobile/samsung-galaxy-a7-16gb-msp5959']
htmlfile = ur.urlopen(url[0])
htmltext = htmlfile.read().decode('UTF-8')
str1 = '<title>(.+?) Price in India 2015'
regex = str1
pattern = re.compile(regex)
titles = re.findall(pattern, htmltext)
print (titles)
str2 = '<strong>(.+?)</strong>'
regex = str2
pattern = re.compile(regex)
attribs = re.findall(pattern, htmltext)
c1 = (len(attribs))
print (c1)
str3 = '<div class="store_rating_bar_out" data-storename="(.+?)"'
regex = str3
pattern = re.compile(regex)
storename = re.findall(pattern, htmltext)
c2 = (len(storename))
print (c2)
str4 = '<div class="store_price">Rs.(.+?)</div>'
regex = str4
pattern = re.compile(regex)
price = re.findall(pattern, htmltext)
c3 = (len(price))
print (c3)
str5 = '<div class="rating" title="(.+?)">'
regex = str5
pattern = re.compile(regex)
rating = re.findall(pattern, htmltext)
c4 = (len(rating))
print (c4)
str6 = '<div class="variant_namein">(.+?) <!--color--></div>'
regex = str6
pattern = re.compile(regex)
variants1 = re.findall(pattern, htmltext)
c5 = (len(variants1))
print (c5)
str7 = '<div class="variant_gostore">(.+?) target='
regex = str7
pattern = re.compile(regex)
variants2 = re.findall(pattern, htmltext)
c6 = (len(variants2))
print (c6)
str8 = '<div class="variant_price">Rs.(.+?)</div>'
regex = str8
pattern = re.compile(regex)
variants3 = re.findall(pattern, htmltext)
c7 = (len(variants3))
print (c7)
import csv
b = open('test1.csv', 'w')
a = csv.writer(b)
data = [c1,c2,c3,c4,c5,c6,c7]
for val in data:
a.writerow([val])
data = [titles, attribs, storename, price, rating, variants1, variants2, variants3]
a.writerows(data)
b.close()