-
Notifications
You must be signed in to change notification settings - Fork 0
/
with_sizes.py
90 lines (72 loc) · 2.78 KB
/
with_sizes.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
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
def send_mail():
import smtplib
from datetime import datetime
gmail_user = 'YOUR_GMAIL'
gmail_password = 'YOUR_GENERATED_PASSWORD'
sent_from = gmail_user
to = ['MAIL_BEING_NOTIFIED']
subject = 'Dischi Disponibili'
body = 'https://www.decathlon.it/p/disco-ghisa-bodybuilding-28mm/_/R-p-7278?mc=1042303&c=NERO \n\n'
email_text = """From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, email_text)
server.close()
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print ('Email sent!', dt_string)
except:
print ('Something went wrong...')
print('running...')
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome("C:\web\chromedriver.exe",options=chrome_options)
driver.get("https://www.decathlon.it/p/disco-ghisa-bodybuilding-28mm/_/R-p-7278?mc=1042303&c=NERO")
time.sleep(3)
driver.find_element(By.CSS_SELECTOR, ".didomi-continue-without-agreeing").click() # rifiuta cookies
isp=0
cool_down = 1800 #sec
while True:
# 5KG
driver.find_element(By.CSS_SELECTOR, ".select:nth-child(4) .svg-icon").click()
time.sleep(1)
#driver.find_element(By.CSS_SELECTOR, "#option-product-size-selection-3 .stock").click()
driver.find_element(By.ID, "option-product-size-selection-3").click() # seleziona dimensione: 0 - 0.5KG; 1 - 1KG; 2 - 2KG; 3 - 5KG; 4 - 10KG; 5 - 20KG
time.sleep(2)
try:
driver.find_element(By.XPATH,"//*[@id='app']/main/article/div[1]/div[6]/section/article/div/button").is_displayed()
#driver.find_element(By.CSS_SELECTOR, ".cta--block").is_displayed()
except:
time.sleep(120)
else:
send_mail()
isp=1
# 10KG
driver.find_element(By.CSS_SELECTOR, ".select:nth-child(4) .svg-icon").click()
time.sleep(1)
#driver.find_element(By.CSS_SELECTOR, "#option-product-size-selection-3 .stock").click()
driver.find_element(By.ID, "option-product-size-selection-4").click() # seleziona dimensione: 0 - 0.5KG; 1 - 1KG; 2 - 2KG; 3 - 5KG; 4 - 10KG; 5 - 20KG
time.sleep(2)
try:
driver.find_element(By.XPATH,"//*[@id='app']/main/article/div[1]/div[6]/section/article/div/button").is_displayed()
#driver.find_element(By.CSS_SELECTOR, ".cta--block").is_displayed()
except:
time.sleep(120)
else:
send_mail()
isp=1
if isp:
time.sleep(cool_down)
isp=0
driver.refresh()
time.sleep(2)