-
Notifications
You must be signed in to change notification settings - Fork 1
/
nike_scrap.py
90 lines (73 loc) · 2.77 KB
/
nike_scrap.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
84
85
86
87
88
89
90
import time
import sys
import validators
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.color import Color
chrome_options = Options()
chrome_options.add_argument('--headless') # No window
chrome_options.add_argument('--log-level=3')
chrome_options.add_argument("--window-size=1920x1080")
driver = webdriver.Chrome(chrome_options=chrome_options)
action = ActionChains(driver)
def main(tailleA, lienA):
if validators.url(lienA):
rep = "\nSIZE FOUND \n" + nike(tailleA, lienA)
driver.delete_all_cookies()
return rep
else:
rep1 = "\nSIZE FOUND \n" + nike(tailleA, cherche(lienA))
driver.delete_all_cookies()
return rep1
def nike(taille, lien):
# taille = input("Taille :")
# lien = input("Lien Nike :")
# delai = float(input("Delai :"))
original_window = driver.current_window_handle
driver.delete_all_cookies()
driver.switch_to.new_window('window')
driver.close()
driver.switch_to.window(original_window)
driver.get(lien)
driver.implicitly_wait(20)
driver.find_element(by=By.XPATH, value='//*[@id="gen-nav-commerce-header-v2"]/div[1]/div/div[2]/div/div[3]/div['
'1]/div[1]').click()
print("COOKIE BYPASS")
size = driver.find_element(by=By.XPATH, value="//*[text()='EU %s']" % taille)
color = driver.find_element(by=By.XPATH, value="//*[text()='EU %s']" % taille).value_of_css_property(
'background-color')
hax = Color.from_string(color).hex
driver.save_screenshot("screenshot.png")
print("SIZE FOUND" + "=" + size.get_attribute('innerHTML'))
driver.maximize_window()
driver.save_screenshot("screenshot.png")
return size.get_attribute('innerHTML') + "=" + check(hax)
def check(hax):
if hax == '#f7f7f7':
return "HORS STOCK"
else:
return "EN STOCK"
def cherche(mot):
if len(mot) != 1:
s = mot.replace(" ", "")
print(s)
driver.get("https://www.nike.com/fr/w?q=%s" % mot)
driver.implicitly_wait(20)
driver.find_element(by=By.XPATH,
value='//*[@id="gen-nav-commerce-header-v2"]/div[1]/div/div[2]/div/div[3]/div[''1]/div[1]').\
click()
up = mot.title()
print(up)
driver.find_element(by=By.XPATH,
value='//*[@id="Wall"]/div/div[6]/div[2]/main/section/div/div[1]/div/figure/a[2]/div/div/img').\
click()
driver.implicitly_wait(20)
s = driver.current_url
return str(s)
if __name__ == "__main__":
tailleA = sys.argv[1]
lienA = sys.argv[2]
main(tailleA, lienA)