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:
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:
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 |
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 # 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.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.