def login_user(self):
        login_post = {'username': self.username, 'password': self.password}

        self.session.headers.update({
            'Origin': self.URL_HOME,
            'Referer': self.URL_HOME,
            'X-Instragram-AJAX': '1',
            'X-Requested-With': 'XMLHttpRequest',
        })

        get_token = self.session.get(self.URL_HOME)
        if get_token:
            print(get_token.cookies['csrftoken'])
            self.session.headers.update(
                {'X-CSRFToken': get_token.cookies['csrftoken']})

        login = self.session.post(self.URL_LOGIN,
                                  data=login_post,
                                  allow_redirects=True)
        if not login.status_code == 200:
            print('Login Error...!!')
            print("Status code: %d" % login.status_code)
        else:
            self.session.headers.update(
                {'X-CSRFToken': login.cookies['csrftoken']})

        res = self.session.get(self.URL_HOME)
        if res.text.find(login_post['username']) == -1:
            print('No username!!')
        utils.save_cookies(self.session)
예제 #2
0
 def request(self, url):
     try:
         self.driver.get(url)
         time.sleep(3)
         # update cookies
         save_cookies(self.driver, self.username)
     except:
         self.driver.execute_script('window.stop()')
예제 #3
0
    def login(self, username, password):
        """Login with provided credentials.

        Arguments:
            username (`str`): the username to log in with
            password (`str`): the password to log in with

        .. note::

            Code taken from LevPasha/instabot.py
        """
        # self.session.cookies.update({
        #     'sessionid': '',
        #     'mid': '',
        #     'ig_pr': '1',
        #     'ig_vw': '1920',
        #     'csrftoken': '',
        #     's_network': '',
        #     'ds_user_id': ''
        # })

        login_post = {'username': username, 'password': password}

        self.session.headers.update({
            'Origin': self.URL_HOME,
            'Referer': self.URL_HOME,
            'X-Instragram-AJAX': '1',
            'X-Requested-With': 'XMLHttpRequest',
        })

        with self.session.get(self.URL_HOME) as res:
            self.session.headers.update(
                {'X-CSRFToken': res.cookies['csrftoken']})
        time.sleep(5 * random.random())  # nosec

        with self.session.post(self.URL_LOGIN,
                               data=login_post,
                               allow_redirects=True) as login:

            self.session.headers.update(
                {'X-CSRFToken': login.cookies['csrftoken']})
            # save_cookies(self.session, 'cookies.txt')
            if not login.status_code == 200:
                raise SystemError("Login error: check your connection")

        with self.session.get(self.URL_HOME) as res:
            if res.text.find(username) == -1:
                raise ValueError('Login error: check your login data')
            save_cookies(self.session)
예제 #4
0
 def verify_credentials(username, password):
     cj = mechanize.MozillaCookieJar()
     br = mechanize.Browser()
     br.set_cookiejar(cj)
     br = utils.setup_browser(br)
     try:
         br.open(urls.BASE_URL)
         try:
             br.select_form(name='login')
             br['login_user'] = username
             br['password'] = password
             #br.find_control(name='autologin').items[0].selected = True
         except mechanize.FormNotFoundError:
             click.echo(
                 'Error occurred. Code VC-FNFE. Kindly contact developer')
             return False
         except NameError:
             click.echo(
                 'Error occurred. Code VC-NE. Kindly contact developer')
             return False
         except mechanize.ControlNotFoundError:
             click.echo(
                 'Error occurred. Code VC-CNFE. Kindly contact developer')
             return False
         br.submit()
         for link in br.links():
             if link.text == 'my account':
                 utils.save_cookies(cj)
                 click.echo('Account Verified!')
                 return True
         click.echo('Wrong Username/Password. Try Again')
         return False
     except mechanize.URLError:
         click.echo(
             'Error in connecting to internet. Please check your internet connection'
         )
         return False
예제 #5
0
    logging.info('Total tasks: %s' % len(local_args))
    success,failure = [],[]

    for provider,arg in local_args:
        sources = download_sources(provider,arg)                
        if arg['no_upload']:
            logger.warn('Not uploading - no_upload sepceified on this resource')
        else:
            result,dirty = upload_sources(sources,arg,report_progress if global_args['show_progress'] else lambda current,max:None )
            if not dirty:success.append((arg,result))
            else: failure.append((arg,None))
    if not failure:sys.exit(0)
    logging.warning('Dirty flag set,not all tasks are done properly')
    sys.exit(1)

if __name__ == "__main__":
    setup_logging()
    global_args,local_args = prase_args(sys.argv)
    '''Parsing args'''
    save_cookies(global_args['cookies'])
    '''Saving / Loading cookies'''    
    if not setup_session(load_cookies()):
        logging.fatal('Unable to set working directory,quitting')
        sys.exit(2)    
    else:
        self_info = sess.Self
        if not 'uname' in self_info['data']:
            logger.error('Invalid cookies: %s' % self_info['message'])        
            sys.exit(2)            
        logger.warning('Bilibili-toolman - operating as %s'  % self_info['data']['uname'])        
        __tasks__()
예제 #6
0
 def save_cookies(self):
     self.login()
     self.wait_for_captcha()
     save_cookies(self.driver, self.username)
예제 #7
0
def login_get_cookies():
    cookies = utils.load_cookies()
    if cookies:
        session = requests.Session()
        session.headers['User-Agent'] = User_Agent
        session.cookies = requests.utils.cookiejar_from_dict(cookies)
        return session,cookies
    chrome_options = Options()
    chrome_options.add_argument("--headless")

    driver = webdriver.Chrome(executable_path='./chromedriver_win32/chromedriver.exe')
    url = 'https://accounts.douban.com/passport/login'
    while 1:
        driver.get(url)
        link = driver.find_element_by_xpath("//ul[@class='tab-start']/li[@class='account-tab-account']")
        link.click()

        name_input = driver.find_element_by_xpath("//div[@class='account-form-field']/input[@id='username']")
        pass_input = driver.find_element_by_xpath("//div[@class='account-form-field']/input[@id='password']")
        remember_input = driver.find_element_by_xpath("//div[@class='account-form-ft']/p[@class='account-form-remember']/input[@id='account-form-remember']")
        login_botton = driver.find_element_by_xpath("//div[@class='account-form-field-submit ']/a[@class='btn btn-account']")
        name_input.clear()
        name_input.send_keys(username)
        pass_input.clear()
        pass_input.send_keys(password)
        remember_input.click()
        login_botton.click()

        start_ts = time.time()
        print("start..",start_ts)

        try:
            WebDriverWait(driver,15).until_not(lambda x:x.find_element_by_xpath("//div[@class='account-form-field-submit ']/a[@class='btn btn-account btn-active']").is_displayed())
            WebDriverWait(driver, 15).until_not(lambda x: x.find_element_by_xpath("//div[@class='account-form-field-submit ']/a[@class='btn btn-account']").is_displayed()) #wait until login
        except:
            import tracback
            print(tracback.format_exc())
            utils.save_html('exc_inex.html',driver.page_source)
            import os
            os._exit(-1)

        print ('end..',time.time()-start_ts)
        driver.save_screenshot('submit.png')
        utils.save_html('index.html',driver.page_source)

        if u'douban' in driver.page_source:
            selenium_cookies = driver.get_cookies()
            print ("selenium_cookies:",selenium_cookies)
            driver.close()
            break
        else:
            driver.close()

    #handle cookies
    session = requests.Session()
    session.headers['User-Agent'] = User_Agent
    for i in selenium_cookies:
        requests.utils.add_dict_to_cookiejar(session.cookies, {i['name']: i['value']})
    cookies = requests.utils.dict_from_cookiejar(session.cookies)
    utils.save_cookies(cookies)
    return session,cookies