-
Notifications
You must be signed in to change notification settings - Fork 0
/
flipkart_scrapper.py
50 lines (33 loc) · 1.27 KB
/
flipkart_scrapper.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
import requests
from bs4 import BeautifulSoup
class flipkartSearch():
def __init__(self, productName,header):
self.productName = str(productName).replace(" ", "+")
self.header = header
def getUrl(self):
url = f"https://www.flipkart.com/search?q={self.productName}&marketplace=FLIPKART"
return url
def makeRequest(self):
request = requests.get(self.getUrl(), headers=self.header)
data = request.content
statusCode = request.status_code
response = {"status-code" : statusCode, "resp" : data}
return response
def getHTML(self):
response = self.makeRequest()["resp"]
soup = BeautifulSoup(response, 'html.parser')
return soup
def toString(self, tags):
for i in range(0,len(tags)):
tags[i] = tags[i].string
return tags
def getNames(self):
names = self.getHTML().findAll('div',{'class':'_4rR01T'})
if(len(names) == 0):
names = self.getHTML().select('a.IRpwTa')
if(len(names) == 0):
names = self.getHTML().select('a.s1Q9rs')
return self.toString(names)
def getPrices(self):
prices = self.getHTML().select('div._30jeq3')
return self.toString(prices)