-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopclues.py
More file actions
55 lines (40 loc) · 1.29 KB
/
shopclues.py
File metadata and controls
55 lines (40 loc) · 1.29 KB
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
from bs4 import BeautifulSoup
import requests
def get_url(search_term):
template= 'https://www.shopclues.com/search?q={}&sc_z=1111&z=0&count=10&user_id=&user_segment=default'
search_term= search_term.replace(' ','%20')
url_f= template.format(search_term)
return url_f
def extract_record(term):
try:
title= term.h2.text.strip()
description= ''
link= 'https:'+ term.a.get('href')
except AttributeError:
return
try:
atag= term.find('div','ori_price')
price= atag.find('span','p_price').text.strip()
disc= atag.find('span','prd_discount').text.strip()
atag3= term.find('div','old_prices')
discprice= atag3.find('span').text.strip()
except AttributeError:
price=''
disc=''
discprice=''
image= term.img.get('src')
results=(title, description,link,price,discprice,disc,image)
return results
product= input('ENTER THE PRODECT')
url= get_url(product)
print(url)
record=[]
while(len(record)<=100):
source= requests.get(url)
soup= BeautifulSoup(source.content, 'html.parser')
result= soup.find_all('div',{'class':'column col3 search_blocks'})
for item in result:
r= extract_record(item)
print(r)
if r:
record.append(r)