-
Notifications
You must be signed in to change notification settings - Fork 0
/
bolScraper.py
91 lines (68 loc) · 3.06 KB
/
bolScraper.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
91
import requests
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import WebDriverException
from selenium.common.exceptions import NoSuchElementException
class bolScraper():
def __init__(self):
self.driver = webdriver.Firefox()
def login(self, email, password):
print('logging in')
self.driver.get("https://www.bol.com/nl/account/login.html")
self.driver.get("https://www.bol.com/nl/account/login.html")
self.driver.find_element_by_id("login_email").send_keys(email)
self.driver.find_element_by_id("login_password").send_keys(password)
self.driver.find_element_by_name("submitLogin").click()
def clickOnMagnifyingGlass(self):
submit = self.driver.find_element_by_class_name("wsp-search__btn")
submit.click()
def addToCartProductsOnPage(self):
print('adding products to cart')
linklist = []
for link in self.driver.find_elements_by_css_selector(".js_preventable_buy_action"):
linklist.append(link.get_attribute('href'))
for link in linklist:
self.driver.get(link)
def selectMaxQuantity(self):
print('getting the quantities')
for i in range(len(self.driver.find_elements_by_id("tst_quantity_dropdown"))):
try:
product = self.driver.find_element_by_id("tst_quantity_dropdown")
select = Select(product)
select.select_by_value('meer')
amount = self.driver.find_element_by_class_name("js_quantity_overlay_input")
amount.send_keys("999")
ok = self.driver.find_element_by_class_name("js_quantity_overlay_ok")
ok.click()
select = Select(self.driver.find_element_by_id("tst_quantity_dropdown"))
print(select.first_selected_option.text)
self.emptyBasketFirstItem()
except NoSuchElementException:
self.emptyBasketFirstItem()
continue
def emptyBasketFirstItem(self):
self.driver.find_element_by_id('tst_remove_from_basket').click()
def goToBasket(self):
self.driver.find_element_by_id('basket').click()
def emptyBasket(self):
linklist = []
print('emptying basket')
self.goToBasket()
for link in self.driver.find_elements_by_id('tst_remove_from_basket'):
linklist.append(link.get_attribute('href'))
for link in linklist:
self.driver.get(link)
if __name__ == "__main__":
email = "[email protected]"
password = "fs065h0Z"
scraper = bolScraper()
scraper.login(email, password)
scraper.emptyBasket()
scraper.clickOnMagnifyingGlass()
scraper.addToCartProductsOnPage()
# scraper.goToBasket()
scraper.selectMaxQuantity()