Skip to content

Multithreading bot using SeleniumBase #2356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fashionprivate opened this issue Dec 10, 2023 · 1 comment
Closed

Multithreading bot using SeleniumBase #2356

fashionprivate opened this issue Dec 10, 2023 · 1 comment
Labels
duplicate The answer/solution already exists somewhere UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@fashionprivate
Copy link

Hello,

I'm implementing a multithreading python bot to scrape a Twitter account.
I implemented scraping using Threads (threading.Thread). In my case I want create about 20 threads that scrape a specific Twitter page account.
The logic I implemented works but the CPU goes to 100% after a few threads (about 10).
I think I'm doing the thread management wrong. How can I optimize the algorithm? Should I use py-test?

from seleniumbase import SB

def start_twitter(args):
    accounts = 20
    threads = []
    
    for index, account in enumerate(accounts):
        # ... ...
        thread = MyThread()
        threads.append(thread)
        thread.start()
    
    for t in threads:
        try:
            t.join()
        except Exception as e:
            pass

class MyThread(threading.Thread):
    def run(self):
        with SB(uc=True, extension_dir="temp/old-twitter-layout-2023/", headless2=True) as sb:
            sb.driver.uc_open("https://www.twitter.com")
            # scraping

The start_twitter(args) method is called from an async def method.

Thanks in advance

@mdmintz mdmintz added duplicate The answer/solution already exists somewhere UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Dec 11, 2023
@mdmintz
Copy link
Member

mdmintz commented Dec 11, 2023

Duplicate of #2006 (comment)

@mdmintz mdmintz marked this as a duplicate of #2006 Dec 11, 2023
@mdmintz mdmintz closed this as completed Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate The answer/solution already exists somewhere UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants