I encountered such a problem that I can not take a separate string from the file for each individual thread in multiprocessing. It turns out only to take a line of one line for all the threads at the same time.
In other words, I want to: First thread = take first line of file; Second thread = take second line of file, etc.
from multiprocessing import Pool
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
import pyperclip
import time
from selenium.webdriver.common.by import By
import multiprocessing
password = "12345"
with open("Token.txt") as f:
content = f.readlines()
content = [x.strip() for x in content]
def get_data(url):
try:
service = Service(r"D:\pythonProject\Test\chromedriver\chromedriver.exe")
chrome_options = Options()
chrome_options.add_extension(
"metamask.crx")
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get(url=url)
time.sleep(5)
driver.switch_to.window(driver.window_handles[1])
driver.get("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html")
time.sleep(2)
driver.switch_to.window(driver.window_handles[1])
driver.get("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html")
time.sleep(2)
start_metamask_button = driver.find_element(By.XPATH,
'//*[@id="app-content"]/div/div[2]/div/div/div/button').click()
time.sleep(3)
import_wallet = driver.find_element(By.XPATH,
'//*[@id="app-content"]/div/div[2]/div/div/div[2]/div/div[2]/div[1]/button').click()
time.sleep(3)
agreed = driver.find_element(By.XPATH,
'//*[@id="app-content"]/div/div[2]/div/div/div/div[5]/div[1]/footer/button[2]').click()
time.sleep(3)
select_word_phrase = Select(
driver.find_element(By.XPATH, '//*[@id="app-content"]/div/div[2]/div/div/div[2]/form/div[1]/div[2]/select'))
select_word_phrase.select_by_visible_text('I have a 24-word phrase')
time.sleep(3)
search_elem = driver.find_element(By.XPATH, '//*[@id="import-srp__srp-word-0"]').click()
time.sleep(2)
pyperclip.copy(content)
print(content)
except Exception as ex:
print(ex)
finally:
driver.quit()
if __name__ == '__main__':
process_count = 3
url = 'chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html'
urls_list = [url] * process_count
print(urls_list)
p = Pool(processes=process_count)
p.map(get_data, urls_list)