-1

I want to write a bot that will open many browsers and log into different accounts on each of them. I'm trying to use Python selenium and multiprocessing. Tell me if it is possible to do this and how. I am attaching an example of my code.

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from config import login, password import time from multiprocessing import Pool import pickle

urls_list = ["https://discord.com/login","https://discord.com/login"]
def get_data(url):
    try:
        options = webdriver.ChromeOptions()
        options.add_argument(
            "User-agent= Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36")
        driver = webdriver.Chrome(
            executable_path="D:\chromedriver.exe",
            options=options
        )
        driver.get(url=url)
        time.sleep(5)

        email_input = driver.find_element(By.CLASS_NAME, "inputField-2RZxdl")
        password_input = driver.find_element(By.NAME, "password")
        email_input.clear()
        password_input.clear()
        email_input.send_keys(f"{login}")
        password_input.send_keys(f'{password}')

        btn_entry = driver.find_element(By.CLASS_NAME, "button-1cRKG6").click()
        time.sleep(4)

        folder_find = driver.find_element(By.CLASS_NAME, "closedFolderIconWrapper-3tRb2d").click()
        time.sleep(1)
        
        project_find = driver.find_element(By.CSS_SELECTOR, "#folder-items-2001708806 > div:nth-child(1) > div:nth-child(2) > div > div > svg > foreignObject > div").click()
        driver.execute_script("window.scrollTo(0, 200)")
        time.sleep(1)
        
        chanel_find = driver.find_element(By.XPATH, '//*[@id="channels"]/ul/li[32]/div/div/a')
        actions = ActionChains(driver)
        actions.move_to_element(chanel_find).perform()
        chanel_find.click()
        time.sleep(1)

        message_find = driver.find_element(By.CSS_SELECTOR, "#message-reactions-1008818995081781248 > div:nth-child(1) > div > div")
        actions.move_to_element(message_find).perform()
        message_find.click()

    except Exception as ex:
        print(ex)
    finally:
        driver.close()
        driver.quit()

if __name__ == "__main__":
    p = Pool(processes=2)
    p.map(get_data, urls_list)
drpsih
  • 1
  • 2

1 Answers1

0

Check this post. What you searching for is probably the ThreadPoolExecutor(). This gave me some help, but you need to try it yourself and I suggest you to minimize your variables as much as you can while testing. Also, this post has a vast implementation if you want multiple threads and the explanation is on point.

Zenul_Abidin
  • 573
  • 8
  • 23
Kabllez
  • 67
  • 6