Esempio n. 1
0
    def initialize_session(self, profile_id):
        '''
        :param profile_id: 
        :return: 
        '''

        try:
            mla_url = 'http://127.0.0.1:35000/api/v1/profile/start?automation=true&profileId=' + profile_id
            resp = requests.get(mla_url)

            json = resp.json()

            # Define DesiredCapabilities
            opts = options.DesiredCapabilities()

            # Instantiate the Remote Web Driver to connect to the browser profile launched by previous GET request
            driver = webdriver.Remote(command_executor=json['value'],
                                      desired_capabilities={})

            return driver

        except Exception as e:
            exception_handler.generic_exception_handler(
                e, exception_handler.func_name())
            return None
Esempio n. 2
0
    start=start+1 if start!=0 else start
    for row in rows[start:]: 
        flagg=False
        counter=0
        print("{}  {}".format(row[1],row[0]))
        # try:
        mla_profile_id = row[0]
        mla_url = 'http://127.0.0.1:35000/api/v1/profile/start?automation=true&profileId='+mla_profile_id
        """
        Send GET request to start the browser profile by profileId. Returns response in the following format: '{"status":"OK","value":"http://127.0.0.1:XXXXX"}', where XXXXX is the localhost port on which browser profile is launched. Please make sure that you have Multilogin listening port set to 35000. Otherwise please change the port value in the url string
        """
        resp = requests.get(mla_url)
        json = resp.json()
        print(json)
        #Define DesiredCapabilities
        opts = options.DesiredCapabilities()
        #Instantiate the Remote Web Driver to connect to the browser profile launched by previous GET request
        driver = webdriver.Remote(command_executor=json['value'], desired_capabilities={})

        #Perform automation
        driver.get('https://www.facebook.com/')
        sleep(2)
        
        #
        done=[]
        runs=random.randint(2,n_funcs-1)
        for _ in range(runs):
            
            while(1):
                index=random.randint(0,n_funcs-1)
                if index not in done:
def runTime(input_file, port, token):
    try:
        file = open(input_file, 'r')
        print('Opened file: ' + input_file)
        outputfile = open('output.txt', 'w')

    except:
        sys.exit('Unable to open file')

    for keyword in file:
        try:
            mla_url = 'http://127.0.0.1:' + port + '/api/v1/profile/start?automation=true&profileId=' + createProfile(
                token, keyword)
        except:
            sys.exit(
                'Unable to create profile - Double check whether Multilogin is running on the correct port and that the token is valid - Terminating'
            )

        # Launch browser
        response = requests.get(mla_url)
        json = response.json()
        opts = options.DesiredCapabilities()

        # Connect Selenium to launched browser
        browser = webdriver.Remote(command_executor=json['value'],
                                   desired_capabilities={})

        browser.get('https://google.com/')

        # Waits for browser to load google, time can be reduced by changing the variable in seconds
        WebDriverWait(browser, 5)
        try:
            search = browser.find_element_by_name('q')
        except:
            print(
                'Unable to find search box on Google - Perhaps try increasing the wait? - Terminating program'
            )
            sys.exit()

        if keyword[-1:] != '\n':
            search.send_keys(keyword + '\n')
        else:
            search.send_keys(keyword)

        try:
            # Waits for browser to load search results page, time can be reduced by changing the variable in seconds
            WebDriverWait(browser, 5).until(
                EC.presence_of_element_located((By.ID, 'reviewDialog')))
        except:
            browser.quit()
            print('Search timed out - Terminating - Keyword: ' + keyword)

        try:
            link = browser.find_element_by_xpath(
                '//*[@id="search"]/div/div/div/div/div/div/div/div/a'
            ).get_attribute('href')
            outputfile.write(keyword.rstrip() + '\n')
            outputfile.write(link + '\n')
        except:
            print('Failed finding link for keyword: ' + keyword)

        browser.close()

    print('Ending search and terminating program')
    file.close()
    outputfile.close()