-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPriceComparison_Scraping.py
54 lines (44 loc) · 1.88 KB
/
PriceComparison_Scraping.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
"""
This Script finds out the prices of two shoes
with different color on club factory
and tells us the best price.
"""
#!/usr/bin/python
import sys
#selenium package is used to automate web browser interaction
from selenium import webdriver
argsLen = len(sys.argv)
if argsLen == 1:
print("Please give the path to chrome driver.")
elif argsLen > 2:
print("Please give the only 1 argument, that is, path to chrome driver. No other argument required.")
#setting the path for the driver
path = str(sys.argv[1])
#path = 'C:/Users\KSHITIJ R. SANGAR\Desktop\Kshitij Projects\Python projects\chromedriver_win32\chromedriver.exe'
#there are different web browsers, so we are using chrome browser, and hence installing its driver
driver = webdriver.Chrome(path)
#the links for the website we want to scrape, that is, extract data from
links = ['https://www.clubfactory.com/amp/item-PID-5448256.html',
'https://cutt.ly/zylaQ5A']
finalPrice = [0,0]
run = True
#using the driver to run on both the links
for i in range(len(links)):
driver.get(links[i])
driver.implicitly_wait(3)
if(run):
#using the method find_element_by_xpath for selecting the gender pop-up
driver.find_element_by_xpath('//*[@id="genderSelectNotification"]/div/div/div[1]/amp-img/img').click()
run = False
#getting the price of the shoe
Price = driver.find_element_by_xpath('//*[@id="product"]/div[3]/div/div/span').text
finalPrice[i] = int(Price[2:])
driver.quit()
#comparing the prices
if finalPrice[0] < finalPrice[1]:
print("\n\n Best Price : ", finalPrice[0], "\n Website = ", links[0],"\n\n")
elif finalPrice[0] > finalPrice[1]:
print("\n\n Best Price : ", finalPrice[1], "\n Website = ", links[1],"\n\n")
else:
#if same price
print("\n\n Both Sites have same prize : ", finalPrice[0], "\n\n")