-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcheckout-bot.py
More file actions
89 lines (72 loc) · 2.8 KB
/
checkout-bot.py
File metadata and controls
89 lines (72 loc) · 2.8 KB
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
import account
import pickle
import time
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class CheckOutBot:
def __init__(self):
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=/home/mike/chrome-checkout")
self.driver = webdriver.Chrome(chrome_options=options)
self.driver.get("https://www.mediamarkt.de/")
# self.accept_cookies()
def accept_cookies(self):
button = self.driver.find_element_by_id("privacy-layer-accept-all-button")
button.click()
def login(self, email, password):
# if os.path.exists("session.data"):
# with open("session.data", "rb") as file:
# cookies = pickle.load(file)
# print("Session loaded from file")
# for cookie in cookies:
# print(cookie)
# self.driver.add_cookie(cookie)
# return True
self.driver.get("https://www.mediamarkt.de/de/myaccount")
time.sleep(5)
email_input = self.driver.find_element_by_id("mms-login-form__email")
email_input.clear()
email_input.send_keys(email)
pass_input = self.driver.find_element_by_id("mms-login-form__password")
pass_input.clear()
pass_input.send_keys(password)
self.driver.find_element_by_id("mms-login-form__login-button").click()
time.sleep(3)
# with open("session.data", "wb") as file:
# pickle.dump(self.driver.get_cookies(), file)
# for cookie in self.driver.get_cookies():
# print(cookie)
def add_product_to_chart(self, link):
self.driver.get(link)
time.sleep(1)
add_to_cart_button = self.driver.find_element_by_css_selector(
'[data-test="a2c-Button"]'
)
time.sleep(2)
def checkout(self):
self.driver.get("https://www.mediamarkt.de/checkout/payment")
time.sleep(1)
self.driver.find_elements_by_class_name(
"SelectGroupstyled__SelectGroupItemContainer-sc-1iooaif-0"
)[2].click()
time.sleep(1)
self.driver.find_elements_by_class_name(
"ContinueButton__StyledContinue-fh9abp-0"
)[1].click()
# this is how you click the final checkout button
# self.driver.find_elements_by_class_name(
# "ContinueButton__StyledContinue-fh9abp-0"
# )[1].click()
def __del__(self):
self.driver.close()
if __name__ == "__main__":
checkout_bot = CheckOutBot()
# checkout_bot.login(account.email, account.password)
# time.sleep(30)
# exit()
checkout_bot.add_product_to_chart(
"https://www.mediamarkt.de/de/product/_sandisk-extreme%C2%AE-2484123.html"
)
checkout_bot.checkout()
time.sleep(20)