Python Forum
Selenium undetected Chromedriver Bot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium undetected Chromedriver Bot
#1
I am trying to create an bot that locates an item checks it for discount and price and then decides to clicks it or not. But the bot isnt able to locate the items using the Xpath i gave him.

It already worked using find by CLASS_NAME but this method is way to slow and i only want to find the lates 12 items on the page. And because, on skinport.com, the Website is updating Live and the items are stacking in the Web Element it wouldnt work after more than 1 minute. Thats why I only want the newest 12 items. The performance of the bot in general is pretty bad. For example the reaction time when a new discounted item pops up. Maybe theres some other other way to do what i wanna do?

code:
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

driver = uc.Chrome()

# navigate to the website you want to open
driver.get('https://skinport.com/de/signin')
# Wait for login
time.sleep(2)
email = driver.find_element(By.ID, "email")
email.send_keys("...")
password = driver.find_element(By.ID, "password")
password.send_keys("...")
#wait for email login
time.sleep(120)
print("started")

while True:

for i in range(1, 13):
    # find new items
    items = driver.find_elements(By.XPATH, f'//*[@id="content"]/div/div[3]/div[2]/div[{i}]/div/div/div[1]/a/div[1]/div[3]/div[1]/div[1]')

# check items for discount and price
for item in items:
    try:
        # check if the price is above 50
        price_element = item.find_element(By.CLASS_NAME, "ItemPreview-priceValue")
        price_text = price_element.find_element(By.CLASS_NAME, "Tooltip-link").text.strip().replace('.', '').replace(',', '.').replace('€', '').strip()
        price = float(price_text)
        if price > 2:
            # check if the discount is above 25%
            discount_element = item.find_element(By.CLASS_NAME, "ItemPreview-discount")
            discount_text = discount_element.text.strip().replace('−', '-')
            match = re.search(r'(\d+)%', discount_text)
            if match:
                discount = float(match.group(1))
                if discount > 5:

                        item.click()
                        # do the rest of the checkout process
                        time.sleep(1)
                        # add to cart
                        add_to_cart_button = driver.find_element(By.CLASS_NAME, "SubmitButton-title")
                        add_to_cart_button.click()
                        # Click shopping cart
                        parent_element = driver.find_element(By.CLASS_NAME, "HeaderContainer-cart")
                        parent_element.click()
                        # submitting shopping cart
                        submit_button = driver.find_element(By.CSS_SELECTOR, ".SubmitButton-title")
                        submit_button.click()
                        time.sleep(0.75)
                        # check checkbox1
                        checkbox = driver.find_element(By.NAME, "cancellation")
                        checkbox.click()
                        # check checkbox2
                        checkbox2 = driver.find_element(By.NAME, 'tradelock')
                        checkbox2.click()
                        time.sleep(0.45)
                        # click buy
                        buy_button = driver.find_element(By.XPATH, "//div[@class=\"SubmitButton-title\" and text()='Zur Kasse gehen']")
                        buy_button.click()
                        time.sleep(0.75)
                        # weiter with giropay
                        giropay_button = driver.find_element(By.XPATH, "//span[contains(text(), 'Weiter zu GiroPay')]")
                        giropay_button.click()
                        time.sleep(840)
                        # wait for a few seconds before checking again
                        time.sleep(0.1)

        except:
            pass
buran write Apr-07-2023, 10:43 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
Sorry for do not having any solution to your problem. May be you can help me with mine. I am also trying to access a website with a webdriver. Your script opens the page itself. Can you tell me how I can use it to access a web page that is already open?
buran write Apr-14-2023, 06:36 AM:
Please, don't hijacked thread. Start new thread describing your problem and providing enough information, code, traceback, data, etc.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  enable flash using selenium chromedriver Fre3k 1 4,300 Nov-27-2020, 12:15 PM
Last Post: JellyCreeper6
  WebDriverException: 'chromedriver' executable needs to be in PATH pyzyx3qwerty 9 12,780 Jun-09-2020, 05:43 PM
Last Post: Yoriz
  Selenium Chromedriver Automation Help lessthanthree 1 2,164 May-05-2020, 11:03 PM
Last Post: Larz60+
  How to identify chromedriver version? metulburr 2 7,687 Jun-13-2019, 11:37 PM
Last Post: metulburr
  Chromedriver launch new tab gahhon 15 10,047 Feb-17-2019, 06:22 PM
Last Post: metulburr
  chromedriver.exe issue gahhon 2 2,842 Feb-12-2019, 12:09 PM
Last Post: metulburr
  Selenium chromedriver and click action Gilles95 4 13,308 Feb-07-2018, 07:28 PM
Last Post: Gilles95
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,649 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020