How to use the instapy.xpath.read_xpath function in instapy

To help you get started, we’ve selected a few instapy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Instagram-Tools / bot / instapy / login_util.py View on Github external
def dismiss_notification_offer(browser, logger):
    """ Dismiss 'Turn on Notifications' offer on session start """
    offer_elem_loc = read_xpath(dismiss_notification_offer.__name__, "offer_elem_loc")
    dismiss_elem_loc = read_xpath(
        dismiss_notification_offer.__name__, "dismiss_elem_loc"
    )

    # wait a bit and see if the 'Turn on Notifications' offer rises up
    offer_loaded = explicit_wait(
        browser, "VOEL", [offer_elem_loc, "XPath"], logger, 4, False
    )

    if offer_loaded:
        dismiss_elem = browser.find_element_by_xpath(dismiss_elem_loc)
        click_element(browser, dismiss_elem)
github Instagram-Tools / bot / instapy / commenters_util.py View on Github external
""" Get the list of users from the 'Likes' dialog of a photo """

    try:
        if check_exists_by_xpath(
            browser, read_xpath(likers_from_photo.__name__, "second_counter_button")
        ):
            liked_this = browser.find_elements_by_xpath(
                read_xpath(likers_from_photo.__name__, "second_counter_button")
            )
            element_to_click = liked_this[0]
        elif check_exists_by_xpath(
            browser, read_xpath(likers_from_photo.__name__, "liked_counter_button")
        ):

            liked_this = browser.find_elements_by_xpath(
                read_xpath(likers_from_photo.__name__, "liked_counter_button")
            )
            likers = []

            for liker in liked_this:
                if " like this" not in liker.text:
                    likers.append(liker.text)

            if " others" in liked_this[-1].text:
                element_to_click = liked_this[-1]

            elif " likes" in liked_this[0].text:
                element_to_click = liked_this[0]

            else:
                print(
                    "Few likes, not guaranteed you don't follow these"
github Instagram-Tools / bot / instapy / story_util.py View on Github external
for item in response["data"]["reels_media"][0]["items"]:
                    if item["taken_at_timestamp"] <= seen:
                        continue
                    else:
                        time.sleep(2)
                        if index == 1:
                            try:
                                next_elem = browser.find_element_by_xpath(
                                    read_xpath(watch_story.__name__, "next_first")
                                )
                            except NoSuchElementException:
                                continue
                        else:
                            try:
                                next_elem = browser.find_element_by_xpath(
                                    read_xpath(watch_story.__name__, "next")
                                )
                            except NoSuchElementException:
                                continue
                        click_element(browser, next_elem)
                        reels_cnt += 1
                        index += 1

            return {"status": "ok", "reels_cnt": reels_cnt}
    else:
        return {"status": "not_ok", "reels_cnt": 0}
github Instagram-Tools / bot / instapy / login_util.py View on Github external
)

    (
        ActionChains(browser)
        .move_to_element(security_code_field)
        .click()
        .send_keys(security_code)
        .perform()
    )

    # update server calls for both 'click' and 'send_keys' actions
    for _ in range(2):
        update_activity(browser, state=None)

    submit_security_code_button = browser.find_element_by_xpath(
        read_xpath(bypass_suspicious_login.__name__, "submit_security_code_button")
    )

    (
        ActionChains(browser)
        .move_to_element(submit_security_code_button)
        .click()
        .perform()
    )

    # update server calls
    update_activity(browser, state=None)

    try:
        sleep(3)
        # locate wrong security code message
        wrong_login = browser.find_element_by_xpath(
github Instagram-Tools / bot / instapy / util.py View on Github external
def get_cord_location(browser, location):
    base_url = "https://www.instagram.com/explore/locations/"
    query_url = "{}{}{}".format(base_url, location, "?__a=1")
    browser.get(query_url)
    json_text = browser.find_element_by_xpath(
        read_xpath(get_cord_location.__name__, "json_text")
    ).text
    data = json.loads(json_text)

    lat = data["graphql"]["location"]["lat"]
    lon = data["graphql"]["location"]["lng"]

    return lat, lon
github Instagram-Tools / bot / instapy / login_util.py View on Github external
)
        except NoSuchElementException:
            logger.warn(
                "Unable to choose ({}) option to bypass the challenge".format(
                    bypass_security_challenge_using.upper()
                )
            )

    # click on your option
    (ActionChains(browser).move_to_element(option).click().perform())
    # next button click will miss the DOM reference for this element, so ->
    option_text = option.text

    # click on security code
    send_security_code_button = browser.find_element_by_xpath(
        read_xpath(bypass_suspicious_login.__name__, "send_security_code_button")
    )
    (ActionChains(browser).move_to_element(send_security_code_button).click().perform())

    # update server calls
    update_activity(browser, state=None)

    print("Instagram detected an unusual login attempt")
    print('Check Instagram App for "Suspicious Login attempt" prompt')
    print("A security code was sent to your {}".format(option_text))

    security_code = None
    try:
        path = "{}state.json".format(logfolder)
        data = {}
        # check if file exists and has content
        if os.path.isfile(path) and os.path.getsize(path) > 0:
github Instagram-Tools / bot / instapy / login_util.py View on Github external
return False

    # check Instagram.com status
    try:
        logger.info("-- Connection Checklist [2/3] (Instagram Server Status)")
        browser.get("https://isitdownorjust.me/instagram-com/")
        sleep(2)
        # collect isitdownorjust.me website information
        website_status = browser.find_element_by_xpath(
            read_xpath(login_user.__name__, "website_status")
        )
        response_time = browser.find_element_by_xpath(
            read_xpath(login_user.__name__, "response_time")
        )
        response_code = browser.find_element_by_xpath(
            read_xpath(login_user.__name__, "response_code")
        )

        logger.info("- Instagram WebSite Status: {} ".format(website_status.text))
        logger.info("- Instagram Response Time: {} ".format(response_time.text))
        logger.info("- Instagram Reponse Code: {}".format(response_code.text))
        logger.info("- Instagram Server Status: ok")
        update_activity(
            browser,
            action=None,
            state="Instagram servers are running correctly",
            logfolder=logfolder,
            logger=logger,
        )
    except Exception:
        logger.warn("- Instagram Server Status: error")
        update_activity(