-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
50 lines (41 loc) · 1.97 KB
/
bot.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
import json
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common import action_chains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.webdriver import WebDriver
def main():
config = dict()
with open("config.json", 'r') as infile:
config = json.load(infile)
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("https://www.amazon.it/dp/B08KKJ37F7")
driver.find_element(By.ID, "sp-cc-accept").click() # accept cookies
# login
driver.find_element(By.ID, "nav-link-accountList").click()
driver.find_element(By.ID, "ap_email").send_keys(config["amazon"]["email"])
driver.find_element(By.ID, "continue").click()
driver.find_element(By.ID, "ap_password").send_keys(config["amazon"]["pass"])
driver.find_element(By.ID, "signInSubmit").click()
driver.implicitly_wait(2) # to refresh every 2 seconds
while(True):
if len(driver.find_elements(By.ID, "buy-now-button")) > 0:
driver.implicitly_wait(10)
driver.find_element(By.ID, "buy-now-button").click()
# Payment method
driver.find_element(By.XPATH, '//input[@type="radio"][' + str(config["amazon"]["method"]) + ']').click()
# Verify card if needed
verify_box = driver.find_element(By.XPATH, '//input[@type="text"]')
if verify_box.is_displayed():
verify_box.send_keys(config["credit_card"]["number"])
driver.find_element(By.XPATH, '//button[text()="Verifica la carta"]').click()
driver.find_element(By.XPATH, '//input[@name="ppw-widgetEvent:SetPaymentPlanSelectContinueEvent"][1]').click()
# BUY
driver.find_element(By.XPATH, '//*[@id="placeYourOrder"]/span/input').click()
driver.close()
else:
driver.refresh()
if __name__ == "__main__":
main()