You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpr_trafficscript1.py 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. import time
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. def search_for_dress(driver, user_id):
  6. url = f'https://{user_id}.cpr-akashop.com/'
  7. driver.get(url)
  8. time.sleep(1)
  9. # Find and click on the magnifying glass icon
  10. magnifying_glass = driver.find_element(By.CSS_SELECTOR, '#header-grid > nav.header--row.header-main.hide-on-mobile.hide-on-tablet.layout-full-contained.nv-navbar.header--row > div > div > div > div.hfg-slot.right > div > div.item--inner.builder-item--header_search_responsive > div > div > a > svg')
  11. magnifying_glass.click()
  12. time.sleep(1)
  13. # Find the search box and search for "dress"
  14. search_box = driver.find_element(By.CSS_SELECTOR, '#header-grid > nav.header--row.header-main.hide-on-mobile.hide-on-tablet.layout-full-contained.nv-navbar.header--row > div > div > div > div.hfg-slot.right > div > div.item--inner.builder-item--header_search_responsive > div > div > div > div.form-wrap > form > input')
  15. search_box.send_keys('dress')
  16. search_box.submit()
  17. time.sleep(3)
  18. # Find and click on the Striped Dress search result
  19. striped_dress_link = driver.find_element(By.CSS_SELECTOR, '#post-82 > div > div > div > div.non-grid-content.alternative-layout-content > h2 > a')
  20. # Scroll to the element
  21. driver.execute_script("arguments[0].scrollIntoView(true);", striped_dress_link)
  22. time.sleep(1) # Add a small delay after scrolling
  23. striped_dress_link.click()
  24. time.sleep(3)
  25. # Add the Striped Dress to the cart
  26. add_to_cart_button = driver.find_element(By.CSS_SELECTOR, '#product-82 > div.nv-single-product-top > div.summary.entry-summary > form > button')
  27. add_to_cart_button.click()
  28. time.sleep(3)
  29. # Click on View Cart
  30. view_cart_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.woocommerce-notices-wrapper > div > a')
  31. view_cart_button.click()
  32. time.sleep(3)
  33. # Scroll to the Proceed to Checkout button
  34. proceed_to_checkout_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.nv-content-wrap.entry-content > div > div.cart-collaterals > div > div > a')
  35. driver.execute_script("arguments[0].scrollIntoView(true);", proceed_to_checkout_button)
  36. time.sleep(1) # Add a small delay after scrolling
  37. # Click on Proceed to Checkout
  38. proceed_to_checkout_button.click()
  39. time.sleep(3)
  40. def main(user_id):
  41. # Chrome
  42. driver = webdriver.Chrome()
  43. search_for_dress(driver, user_id)
  44. driver.quit()
  45. if __name__ == "__main__":
  46. user_id = input("Please enter your user ID: ") # Ask for the user ID only once
  47. main(user_id)