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_trafficscript2.py 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. import time
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.chrome.service import Service as ChromeService
  6. from selenium.webdriver.chrome.options import Options
  7. from webdriver_manager.chrome import ChromeDriverManager
  8. def search_for_dress(driver, user_id):
  9. url = f'https://{user_id}.cpr-akashop.com/'
  10. driver.get(url)
  11. print(f"Navigated to {url}")
  12. time.sleep(1)
  13. # Find and click on the magnifying glass icon
  14. 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')
  15. magnifying_glass.click()
  16. print("Clicked on magnifying glass icon")
  17. time.sleep(1)
  18. # Find the search box and search for "dress"
  19. 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')
  20. search_box.send_keys('dress')
  21. search_box.submit()
  22. print("Searched for 'dress'")
  23. time.sleep(3)
  24. # Find and click on the Striped Dress search result
  25. striped_dress_link = driver.find_element(By.CSS_SELECTOR, '#post-82 > div > div > div > div.non-grid-content.alternative-layout-content > h2 > a')
  26. # Scroll to the element
  27. driver.execute_script("arguments[0].scrollIntoView(true);", striped_dress_link)
  28. time.sleep(1) # Add a small delay after scrolling
  29. striped_dress_link.click()
  30. print("Clicked on the Striped Dress link")
  31. time.sleep(3)
  32. # Add the Striped Dress to the cart
  33. add_to_cart_button = driver.find_element(By.CSS_SELECTOR, '#product-82 > div.nv-single-product-top > div.summary.entry-summary > form > button')
  34. add_to_cart_button.click()
  35. print("Added Striped Dress to the cart")
  36. time.sleep(3)
  37. # Click on View Cart
  38. view_cart_button = driver.find_element(By.CSS_SELECTOR, '#content > div > div > div > div.woocommerce-notices-wrapper > div > a')
  39. view_cart_button.click()
  40. print("Clicked on View Cart")
  41. time.sleep(3)
  42. # Scroll to the Proceed to Checkout button
  43. 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')
  44. driver.execute_script("arguments[0].scrollIntoView(true);", proceed_to_checkout_button)
  45. time.sleep(1) # Add a small delay after scrolling
  46. # Click on Proceed to Checkout
  47. proceed_to_checkout_button.click()
  48. print("Clicked on Proceed to Checkout")
  49. time.sleep(3)
  50. def main(user_id):
  51. # Set up Chrome options
  52. chrome_options = Options()
  53. chrome_options.add_argument("--headless") # Run headless Chrome
  54. chrome_options.add_argument("--disable-gpu") # Disable GPU acceleration
  55. chrome_options.add_argument("--window-size=1920,1200") # Set window size to avoid issues with elements being out of view
  56. # Use WebDriverManager to automatically manage the ChromeDriver installation
  57. service = ChromeService(ChromeDriverManager().install())
  58. driver = webdriver.Chrome(service=service, options=chrome_options)
  59. search_for_dress(driver, user_id)
  60. driver.quit()
  61. print("Browser closed")
  62. if __name__ == "__main__":
  63. user_id = input("Please enter your user ID: ") # Ask for the user ID only once
  64. main(user_id)