コード例 #1
0
def do_favo(driver):
    try:
        # いいねボタンの要素
        xpath = '/html/body/div[5]/div[2]/div/article/div[3]/section[1]/span[1]/button'
        elm = es.get_elm_by_xpath(driver, xpath)

        # いいね済みかどうかの判定
        icon = elm.find_element_by_tag_name('svg')
        is_favoed = icon.get_attribute('aria-label')
        if(is_favoed == 'いいね!'):
            
            # いいね!
            elm.click()
            es.wait(1)

            # いいねしたらTrueを返す
            return True

        # いいねしなかったらFalseを返す
        return False

    except:
        function = sys._getframe().f_code.co_name
        message = 'いいね!に失敗しました。'
        es.notice_error(module, function, message)
コード例 #2
0
def get_favo_user_list(driver, set_reach):
    try:
        # 格納用
        user_urls = set([])

        # 取得するループ
        while(True):
            # ユーザーのURLを取得
            xpath = '/html/body/div[6]/div/div/div[2]/div/div/div[1]'
            elm = es.get_elm_by_xpath(driver, xpath)
            url_elm = elm.find_element_by_tag_name('a')
            user_url = url_elm.get_attribute('href')
            user_urls.add(user_url)
            
            # リーチ数分取得したらループから抜ける
            if(len(user_urls) >= set_reach):
                break
            
            # 1つ分スクロール
            elm_height = elm.size["height"]
            selector = 'body > div.RnEpo.Yx5HN > div > div > div.Igw0E.IwRSH.eGOV_.vwCYk.i0EQd > div'
            es.scroll(driver, selector, elm_height)
            es.wait(0.1, 0.1)

        return user_urls

    except:
        function = sys._getframe().f_code.co_name
        message = 'いいねするユーザーリストの取得に失敗しました。'
        es.notice_error(module, function, message)
コード例 #3
0
def move_to_login_form(driver):
    try:
        move_form_xpath = '/html/body/div[1]/section/main/article/div[2]/div/div/div[3]/span/button'
        move_form_elm = es.get_elm_by_xpath(driver, move_form_xpath)
        move_form_elm.click()
        es.wait()
    except:
        function = sys._getframe().f_code.co_name
        message = 'ログインフォームへの遷移(セッションなし)に失敗しました。'
        es.notice_error(module, function, message)
コード例 #4
0
def get_post_url_from_post_list(post):
    try:
        # 投稿のURLを取得
        elm_url = es.get_elm_by_xpath(post, "a")
        url = elm_url.get_attribute('href')
        return url

    except:
        function = sys._getframe().f_code.co_name
        message = '投稿のURL取得に失敗しました。'
        es.notice_error(module, function, message)
コード例 #5
0
def oparate_login_session(driver, login_id, login_pass):
    try:
        # IDを入力
        # インプット要素取得
        id_xpath = '/html/body/div[5]/div/div/div[2]/div/div/div/form/div[1]/div[1]/div/label/input'
        id_elm = es.get_elm_by_xpath(driver, id_xpath)
        # 中身削除
        id_elm.send_keys(Keys.CONTROL + "a")
        es.wait(0)
        id_elm.send_keys(Keys.DELETE)
        es.wait(0)
        # ID入力
        id_elm.send_keys(login_id)
        es.wait(1)

        # パスワードを入力
        # インプット要素取得
        pass_xpath = '/html/body/div[5]/div/div/div[2]/div/div/div/form/div[1]/div[2]/div/label/input'
        pass_elm = es.get_elm_by_xpath(driver, pass_xpath)
        # 中身削除
        pass_elm.send_keys(Keys.CONTROL + "a")
        es.wait(0)
        pass_elm.send_keys(Keys.DELETE)
        es.wait(0)
        # ID入力
        pass_elm.send_keys(login_pass)
        es.wait(1)

        # ログインボタンクリック
        btn_xpath = '/html/body/div[5]/div/div/div[2]/div/div/div/form/div[1]/div[4]/button'
        btn_elm = es.get_elm_by_xpath(driver, btn_xpath)
        btn_elm.click()
        es.wait()

    except:
        function = sys._getframe().f_code.co_name
        message = 'ログイン操作(セッションあり)に失敗しました。'
        es.notice_error(module, function, message)
コード例 #6
0
def move_to_login_form_session(driver):
    try:
        # アカウントアイコンをクリック
        icon_xpath = '/html/body/div[1]/section/nav/div[2]/div/div/div[3]/div/div[5]/span/img'
        icon_elm = es.get_elm_by_xpath(driver, icon_xpath)
        icon_elm.click()
        es.wait()
        
        # アカントを切り替えるボタンをクリック
        change_xpath = '/html/body/div[1]/section/nav/div[2]/div/div/div[3]/div/div[5]/div[2]/div[2]/div[2]/div[1]/div'
        change_elm = es.get_elm_by_xpath(driver, change_xpath)
        change_elm.click()
        es.wait()

        # 既存のアカウントにログインをクリック
        btn_xpath = '/html/body/div[5]/div/div/div[3]/button'
        btn_elm = es.get_elm_by_xpath(driver, btn_xpath)
        btn_elm.click()
        es.wait()

    except:
        function = sys._getframe().f_code.co_name
        message = 'ログインフォームへ移動(セッションあり)に失敗しました。'
        es.notice_error(module, function, message)
コード例 #7
0
def get_post_text(driver):
    try:
        # 投稿文取得
        post_xpath = '/html/body/div[1]/section/main/div/div[1]/article/div[3]/div[1]/ul/div/li/div/div/div[2]/span'
        post_elm   = es.get_elm_by_xpath(driver, post_xpath)
        post_text  = post_elm.get_attribute('innerHTML')

        # ハッシュタグ削除
        tags = post_elm.find_elements_by_tag_name('a')
        for tag in tags:
            post_text = post_text.replace(str(tag.get_attribute('outerHTML')), '')

        return post_text

    except:
        function = sys._getframe().f_code.co_name
        message = '投稿文の取得に失敗しました。'
        es.notice_error(module, function, message)
コード例 #8
0
def get_post_num(driver):
    try:
        # 投稿数取得
        xpath = '/html/body/div[1]/section/main/div/header/section/ul/li[1]/span/span'
        elm = es.get_elm_by_xpath(driver, xpath)
        post_num = elm.text

        # 数値型に変換
        if(post_num == 'NaN'):
            post_num = 0
        elif("万" in post_num):
            post_num = int(float(post_num.replace("万","")) * 1000)
        else:
            post_num = int(post_num)

        return post_num

    except:
        function = sys._getframe().f_code.co_name
        message = '投稿数の取得に失敗しました。'
        es.notice_error(module, function, message)