I worked with selenium in python. I wanted to make the program multithreaded (4-10 threads) but it wont work. I don't know why.
When I start: Output: Thread started!
What should happen: Output: Thread started! Thread started! Thread started! Thread started! Thread started! ...
Here is what I tried:
from selenium import webdriver
import string
import random
import time
from threading import Thread
def bot():
while True:
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging']) # Disables logging
options.add_argument('--disable-extensions')
options.add_argument('--profile-directory=Default')
options.add_argument("--incognito")
options.add_argument("--disable-plugins-discovery");
options.add_argument("--headless") # Turns Chrome into headless browser
options.add_argument("--mute-audio")
driver = webdriver.Chrome(options=options)
driver.get("https://example.com/")
driver.close()
def main():
for _ in range(10):
print("Thread started!")
worker = Thread(target=bot())
worker.setDaemon(True)
worker.start()
if __name__ == '__main__':
main()