-
Notifications
You must be signed in to change notification settings - Fork 38
/
snapdeal_spider.py
executable file
·62 lines (56 loc) · 1.65 KB
/
snapdeal_spider.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
import requests
from bs4 import BeautifulSoup
url=raw_input('Enter the Snapdeal Product url: ')
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'}
source_code = requests.get(url, headers=headers, timeout=5)
plain_text=source_code.text
soup=BeautifulSoup(plain_text,"html.parser")
#Product Name
#print soup
link=soup.find('h1',{'class':'pdp-e-i-head'})
title=link.string
title=str(title).strip()
print 'Product: '+title
#Price
link2=soup.find('span',{'itemprop':'price'})
cost=link2.string
print 'Price: Rs. '+cost
#EMI
try:
link3=soup.find('span',{'class':'emi-price'})
emi=link3.string
except:
emi='Not Available'
print 'EMI Status: '+emi
#Ratings
try:
link4=soup.find('span',{'class':'avrg-rating'})
ratings=link4.string
except:
ratings="No ratings yet."
print "Ratings(out of 5): "+ratings
#No. of ratings
try:
link5=soup.find('span',{'class':'total-rating showRatingTooltip'})
reviews=link5.string
except:
reviews="No ratings yet."
print 'Ratings Available: '+reviews
#Bread-crumbs
crumbs=soup.find('div',{"class":"comp-breadcrumb"}).findAll('span')
x=len(crumbs)
print 'Bread-crumbs:'
for i in range(x):
if crumbs[i].string!=None:
print crumbs[i].string,
table=soup.findAll('table',{"class":"product-spec"})
len_table=len(table)
specs={}
print '\n'
print "Specifications :--"
for i in range(len_table):
cols = table[i].find_all('td')
for j in range(0,len(cols),2):
specs[cols[j].string]=cols[j+1].string
for k, v in specs.items():
print (str(k), str('-->'), str(v))