-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathamazon_fresh_delivery_slot_chrome.py
64 lines (47 loc) · 1.76 KB
/
amazon_fresh_delivery_slot_chrome.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
import bs4
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import sys
import time
import os
def getWFSlot(productUrl):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
}
driver = webdriver.Chrome()
driver.get(productUrl)
html = driver.page_source
soup = bs4.BeautifulSoup(html)
time.sleep(60)
no_open_slots = True
while no_open_slots:
driver.refresh()
print("refreshed")
html = driver.page_source
soup = bs4.BeautifulSoup(html)
time.sleep(2)
no_open_slots = "No doorstep delivery windows are available for"
try:
no_slots_from_web = driver.find_element_by_xpath('/html/body/div[5]/div/div/div[2]/div/div/form/div[3]/div[4]/div/div[2]/div[2]/div[6]/div/div[2]/div/div[2]/div/div[20]/div[1]/div[1]/div/div/div/span').text
if no_open_slots in no_slots_from_web:
pass
else:
print('SLOTS OPEN!')
os.system('say "Slots for delivery opened!"')
no_open_slots = False
time.sleep(1400)
except NoSuchElementException:
print('SLOTS OPEN!')
os.system('say "Slots for delivery opened!"')
no_open_slots = False
time.sleep(1400)
try:
open_slots = soup.find('div', class_ ='orderSlotExists').text()
if open_slots != "false":
print('SLOTS OPEN!')
os.system('say "Slots for delivery opened!"')
no_open_slots = False
time.sleep(1400)
except AttributeError:
pass
getWFSlot('https://www.amazon.com/gp/buy/shipoptionselect/handlers/display.html?hasWorkingJavascript=1')