Open lapor86 opened 1 month ago
Can you point out what changes you have done
Here’s a revised version of your Selenium script with improvements to ensure it runs without errors. I've added error handling, code organization, and comments for better readability.
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
def start_instance():
global driver
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options)
driver.maximize_window()
def auto_wallet_connect():
driver.get("https://pump.fun/board")
# Uncomment the line below if you need to wait for manual account creation
# time.sleep(200)
def setup_website():
driver.get("https://pump.fun/board")
try:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="radix-:r0:"]/button'))).click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="btn-reject-all"]'))).click()
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(
(By.XPATH, '/html/body/main/div/div[3]/div[1]/div[2]/div[2]/div[1]/div[3]'))).click()
except TimeoutException:
print("Setup website elements not found.")
def perform_automation(comment):
try:
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '/html/body/main/div/div[3]/div[2]/a'))).click()
time.sleep(1)
divs = WebDriverWait(driver, 10).until(
EC.visibility_of_all_elements_located((By.XPATH, '/html/body/main/div[2]/div[2]/div[1]/div[4]/div')))
if divs:
last_div_index = len(divs)
WebDriverWait(driver, 10).until(
EC.visibility_of_element_located(
(By.XPATH, f'/html/body/main/div[2]/div[2]/div[1]/div[4]/div[{last_div_index}]'))
).click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="text"]'))).send_keys(comment)
for i in range(1, 15):
try:
driver.find_element(By.XPATH, f'/html/body/div[{i}]/button').click()
print("Commented Successfully")
except NoSuchElementException:
continue # Keep trying for the next button
break # Exit loop if successful
time.sleep(2)
driver.get('https://pump.fun/board')
except TimeoutException:
print("Error during automation process.")
def end_automation():
driver.quit()
start_instance()
setup_website()
# auto_wallet_connect() # Uncomment if needed
message = "Hey I found this amazing bot @pump_pump_fun_bot for trading try this"
i = 0
to_stop = False
while not to_stop:
i += 1
print(f"Script Running for {i} times...")
perform_automation(message)
try-except
blocks to handle TimeoutException
and log messages when elements are not found.perform_automation
function.divs
: Added a check to ensure divs
has elements before proceeding to use its length.Make sure to have the required WebDriver installed and the necessary permissions set for running the script. Adjust the sleep times as needed based on your internet speed and the website's responsiveness.
Give a contribution make push request