-
Hi Everyone, I am trying to run SB in parallel. in this code I am expecting output to be:
but as soon as I activate uc=True or even with uc_subprocess=True. I even tried passing user_data_dir also, it gives out all sorts of problems like this:
or this
Or even sometimes only one window is opening all urls, and others getting stalled. and does not even quit. from seleniumbase import SB
import concurrent.futures
def run_instance(url):
with SB(uc=True, uc_subprocess=True) as sb:
sb.open(url)
sb.sleep(5)
title = sb.get_page_title()
return f"URL: {url} - Title: {title}"
if __name__ == '__main__':
# List of URLs to process
urls = [
"https://google.com/ncr",
"https://www.python.org",
"https://www.example.com",
"https://www.wikipedia.org",
"https://www.github.com",
# Add more URLs as needed
]
# Run the instances with 5 parallel workers
with concurrent.futures.ProcessPoolExecutor(max_workers=5) as executor:
results = executor.map(run_instance, urls)
# Print the title retrieved from each URL
for result in results:
print(result) so I suppose UC mode does not support multithreading or multiprocessing. is there a way I can parallelize opening urls in different windows using UC mode? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
See the example for multithreading with CDP Mode: Also see SeleniumBase/examples/raw_multi_drivers.py You'll need to use |
Beta Was this translation helpful? Give feedback.
See the example for multithreading with CDP Mode:
SeleniumBase/examples/cdp_mode/raw_multi_cdp.py
Also see SeleniumBase/examples/raw_multi_drivers.py
You'll need to use
ThreadPoolExecutor
.