gologinapp / pygologin

REST API provides programmatic access to GoLogin App. Create a new browser profile, get a list of all browser profiles, add a browser profile and running
Other
61 stars 42 forks source link

Cannot work on multiple browsers at same time when using multiprocessing. #74

Open iamumairayub opened 7 months ago

iamumairayub commented 7 months ago

I am using your example from github https://github.com/gologinapp/pygologin/blob/main/gologin/gologin-selenium-multiprocess.py

I have 3 profiles created, but when I want to do multiprocessing, only 1 browser works and other browsers stays idle.

I want to run like multiple concurrent browsers at same time, independently.

https://www.awesomescreenshot.com/video/22763698?key=69c71d18e9e2b29c24fcfab9b616632c

What I am doing wrong?

def scrap(profile):
    gl = GoLogin({
            'token': 'token',
            'profile_id': profile['profile_id'],
        })

    chrome_driver_path = r'C:\chromedriver.exe'

    service = Service(executable_path=chrome_driver_path)
    debugger_address = gl.start()
    chrome_options = Options()
    chrome_options.add_experimental_option("debuggerAddress", debugger_address)
    driver = webdriver.Chrome(service=service, options=chrome_options)
    driver.get("https://www.whatismybrowser.com/")
    print('ready', profile['profile_id'], driver.title)
    print('closing', profile['profile_id'])
    driver.quit()
    time.sleep(3)
    gl.stop()

if __name__ == '__main__':

    profiles = [
        {'profile_id': '6562f42979492fef9533b4f0'}, 
        {'profile_id': '6562f42179492fef9533b4e8'},
        {'profile_id': '6562f419b7ecde60c784e8d8'},
        ]

    with Pool(3) as p:
        p.map(scrap, profiles)

    if platform == "win32":
        # os.system('taskkill /im chrome.exe /f')
        os.system('taskkill /im chromedriver.exe /f')
    else:
        # os.system('killall -9 chrome')
        os.system('killall -9 chromedriver')

FYI, I am running this code in Windows 10 and have your app installed, I created 3 profiles in that app. Also, in your example code I can see a port option, where do I get port number for each profile?

Roman-Kasianenko commented 4 months ago

@iamumairayub, hi. I guess to make it work as expected you have to specify port when you create instance if GoLogon, something like this gl = GoLogin({ "token": GO_TOKEN, "profile_id": profile_id, 'port': random.randint(3500, 9999) }) so, for each profile you need to create new instance and specify new port for each instance