I'm making a bot for PlayStation 5. And restock is coming soon so I want to make my bot faster. The approximate duration is 4.90 seconds. Is there any way to make this faster? I found that I should write this in C or C ++ for better results.
#startup
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver = webdriver.Chrome('chromedriver')
driver.maximize_window()
driver.get("https://www.games.rs/ps4-konzole/16794-konzola-playstation-4-1tb-pro-black-dualshock-fifa-21")
Cena and Kupi are unnecessary. Program clicks to accept cookies. Then scrolling cuz it needs to. And then refreshing page until text in button is "Add to Cart".
#order
start_time = time.time()
kupi = driver.find_element_by_xpath('//*[@class="block product-attributes-wrapper clearfix"]/ul[1]/li[1]/div[1]/div[1]')
cena = driver.find_element_by_xpath('//*[@class="block product-attributes-wrapper clearfix"]/ul[1]/li[1]/div[1]/div[1]')
driver.find_element_by_xpath('//*[@id="modal-cookie-info"]/div/div/div/div/button').click()
driver.execute_script("window.scrollTo(712, 200);", kupi)
while True:
try:
driver.find_element_by_xpath('//button[text()="Dodaj u korpu"]')
except NoSuchElementException:
driver.refresh()
else:
driver.find_element_by_xpath('//button[text()="Dodaj u korpu"]').click()
break
driver.find_element_by_xpath('//*[@id="miniCartContent"]/div[1]/a').click()
driver.execute_script("window.scrollTo(0 , 900);", )
Lastly login for informations and completing order.
#login
driver.find_element_by_xpath('//*[@id="order_address_content"]/div/div/div[2]/div[2]/div[1]/div[1]/div[2]/div/div/a').click()
time.sleep(0.2)
email = driver.find_element_by_css_selector('#login_email')
email.send_keys("mail")
password = driver.find_element_by_id('login_password')
password.send_keys("pass")
driver.find_element_by_xpath('//*[@id="login_modal"]/div/div/form/div[3]/button').click()
time.sleep(0.2)
driver.execute_script("window.scrollTo(0 , 1600);", )
driver.find_element_by_xpath('//*[@class="delivery-options list-unstyled"]/li[3]/div[1]/div[1]').click()
time.sleep(0.5)
driver.execute_script("window.scrollTo(0 , 2500);", )
driver.find_element_by_xpath('//*[@id="submit_order_one_page"]').click()
This prints duration of the program.
print("--- %s seconds ---" % (time.time() - start_time))