コード例 #1
0
ファイル: ig_manip.py プロジェクト: stefanlivnjak/ig_manip
def login(driver, username, password):
	driver.get("https://www.instagram.com/accounts/login/")

	waiter.find_write(driver, "//div/input[@name='username']", username, by=XPATH)
	waiter.find_write(driver, "//div/input[@name='password']", password, by=XPATH)
	waiter.find_element(driver, "//div/button[@type='submit']", by=XPATH).click()

	waiter.find_element(driver, "//a/span[@aria-label='Find People']", by=XPATH)
コード例 #2
0
def get_name_suggestion(driver, name):
    # Find the search box, clear it, write the name
    waiter.find_write(driver, 'searchboxinput', name, by=ID, clear_first=True)

    class SuggestionLoads(object):
        def __init__(self):
            self._last_seen = None

        def __call__(self, driver):
            """ Custom expected condition.
                Returns either the first suggested name, or '<No Suggestion>'
                Raises a TimeoutException in the event the page source is different
            """
            suggestion_icon = 'div.suggest-icon-container'
            suggest_css = 'div.suggest-left-cell > span.suggest-query'
            try:

                # Only want suggestions that have the location icon next to them, and not the
                # magnifying glass. Return False if we don't find any so as to retry
                icons = driver.find_elements_by_css_selector(suggestion_icon)
                if len(icons) < 1:
                    return False

                elems = driver.find_elements_by_css_selector(suggest_css)

                if len(elems) == 0:
                    # No suggestions have loaded yet, return False so the Wait can retry
                    return False

                suggest_text = elems[0].text
                if len(suggest_text) == 1:
                    # Sometimes we catch text mid-update. Return False to retry
                    # and hopefully get the whole suggestion
                    return False
                elif suggest_text == NO_SUGGESTION:
                    # Google has no suggestion for us, return NO_SUGGESTION, which the Wait will
                    # evaluate as True and exit
                    return '<No Suggestion>'
                else:
                    # We found a valid suggestion. We need to make sure nothing else is going to
                    # get AJAXed in, so compare it to or _last_seen property. If they match,
                    # everything has stabilized and return the string, which will be evaluated as
                    # True and cause the Wait to exit
                    # If you don't do this, you wind up with jung suggestions like "Traffic"
                    if suggest_text == self._last_seen:
                        return suggest_text
                    else:
                        self._last_seen = suggest_text
                        return False

            except StaleElementReferenceException:
                # Because the DOM is constantly updating, there is a pretty decent chance that a
                # SERE will get thrown. Catch it if it does and return False so the Wait
                # can try again
                return False

    return Wait(driver, 30).until(SuggestionLoads())
コード例 #3
0
def login(driver):
    username = #insert username here
    password = #insert password here

    # Load page
    driver.get("https://www.instagram.com/accounts/login/")

    # Login
    waiter.find_write(driver, "//input[@name='username']", username, by=XPATH)
    waiter.find_write(driver, "//input[@name='password']", password, by=XPATH)
    waiter.find_element(driver, "//div/button[@type='submit']", by=XPATH).click()

    # Wait for the user dashboard page to load
    waiter.find_element(driver, "//a/span[@aria-label='Find People']", by=XPATH)
コード例 #4
0
def login(driver, user, pwd):

    driver.get("https://www.instagram.com/accounts/login/")

    # find and write in input fields to login
    waiter.find_write(driver, "//div/input[@name='username']", user, by=XPATH)
    waiter.find_write(driver, "//div/input[@name='password']", pwd, by=XPATH)
    # submit
    waiter.find_element(driver, "//div/button[@type='submit']",
                        by=XPATH).click()

    # waits until the homepage loads before exiting function
    waiter.find_element(driver,
                        "//a/span[@aria-label='Find People']",
                        by=XPATH)
コード例 #5
0
def login(driver):
    username = ""
    password = ""

    driver.get("http://danharoo.com/member/login.html")

    waiter.find_write(driver, "//*[@id='member_id']", username, by=XPATH)
    waiter.find_write(driver, "//*[@id='member_passwd']", password, by=XPATH)
    submit = driver.find_element_by_xpath(
        "/html/body/div[4]/div/div/form/div/div/fieldset/a")
    submit.click()

    waiter.find_element(
        driver,
        "//*[@id='contents_main']/div[1]/div[1]/ul/li[11]/a/img",
        by=XPATH)
コード例 #6
0
 def Login(self):
     # Check that if we already logged in there is no need to do it again
     if self.loggedin is True:
         print("Already Logged in")
         return 1
     try:
         # Open driver and load cookies
         self.driver.get("https://www.instagram.com/accounts/login")
         cookies = pickle.load(open(self.cookiepath, "rb"))
         for cookie in cookies:
             if "expiry" in cookie:
                 del cookie["expiry"]
             self.driver.add_cookie(cookie)
         time.sleep(round(random.uniform(5, 7), 2))
         # Check if we are not already logged in on last session
         cururl = self.driver.current_url
         if cururl == "https://www.instagram.com/":
             print("Already Logged In no need To Login")
             return -1
         # Everything is fine we are logged in Let's fill the form
         waiter.find_write(self.driver, "//input", self.username, by=XPATH)
         time.sleep(round(random.uniform(2, 3), 2))
         waiter.find_write(self.driver,
                           "//div[3]/div/label/input",
                           self.password,
                           by=XPATH)
         time.sleep(round(random.uniform(2, 3), 2))
         waiter.find_element(self.driver, "//button/div", by=XPATH).click()
         time.sleep(round(random.uniform(4, 6), 2))
         # Check if login was successful
         cururl = self.driver.current_url
         if cururl == "https://www.instagram.com/":
             print("Login success")
             pickle.dump(self.driver.get_cookies(),
                         open(self.cookiepath, "wb"))
             self.loggedin = True
             return 0
         # We didn't get to the main page so there was a problem
         else:
             print("Error: Login Was not successful")
             return -1
     except Exception as err:
         print("Error: in Login")
         traceback.print_exc()
         print(str(err))
         return -1
コード例 #7
0
def login(driver, username, password):
    '''
    Logs into instagram.
    '''
    # load page
    driver.get("https://www.instagram.com/accounts/login/")

    # login
    waiter.find_write(driver,
                      "//div/label/input[@name='username']",
                      username,
                      by=XPATH)
    waiter.find_write(driver,
                      "//div/label/input[@name='password']",
                      password,
                      by=XPATH)
    waiter.find_element(driver, "//div/button[@type='submit']",
                        by=XPATH).click()

    # wait for the page to load. increase from 5 if internet is slow
    time.sleep(5)
    print("login complete.\n")
コード例 #8
0
ファイル: log_in_page.py プロジェクト: ssgalitsky/instabrade
 def log_in_username(self, username):
     """ Sets the text in the username field to `username` """
     waiter.find_write(self.driver, 'username', username, by=NAME)
コード例 #9
0
ファイル: log_in_page.py プロジェクト: ssgalitsky/instabrade
 def log_in_password(self, password):
     """ Sets the text in the password field to `password` """
     waiter.find_write(self.driver, 'password', password, by=NAME)
コード例 #10
0
    password_field = waiter.find_element(driver, "password", By.ID)
    password_field.click()
    password_field.send_keys("my_password")

    login_button = waiter.find_element(driver, "input.btn-primary",
                                       By.CSS_SELECTOR)
    login_button.click()
finally:
    driver.quit()

from explicit import waiter
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

try:
    driver.get("https://github.com/this/doesntexist")

    waiter.find_write(driver, "login_field", "my_username", by=By.ID)

    waiter.find_write(driver,
                      "password",
                      "my_password",
                      by=By.ID,
                      send_enter=True)

finally:
    driver.quit()