コード例 #1
0
def move_to_profile_from_post(driver):
    try:
        # プロフィール画面に遷移
        xpaths = [
            '/html/body/div[1]/section/main/div/div/article/header/div[2]/div[1]/div[1]/a',
            '/html/body/div[1]/section/main/div/div[1]/article/header/div[2]/div[1]/div[1]/span/a'
        ]
        elm = es.get_elm_by_xpaths(driver, xpaths)
        driver.get(elm.get_attribute('href'))
        es.wait()
    
    except:
        function = sys._getframe().f_code.co_name
        message = 'プロフィール画面への遷移に失敗しました。'
        es.notice_error(module, function, message)
コード例 #2
0
def do_follow(driver, max_follow, follow_count):
    try:
        xpaths = [
            '/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/div/span/span[1]/button',
            '/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/button'
        ]
        elm = es.get_elm_by_xpaths(driver, xpaths)
        elm_text = elm.text

        if(elm_text == 'フォローする' and max_follow > follow_count):
            elm.click()
            es.wait()
            return True
        return False
    except:
        function = sys._getframe().f_code.co_name
        message = 'フォローに失敗しました。'
        es.notice_error(module, function, message)
コード例 #3
0
def save_file_part(driver, xpaths, ind):
    try:
        # Xpathのリストから画像/動画を取得
        content = es.get_elm_by_xpaths(driver, xpaths)
        response = requests.get(content.get_attribute('src')).content

        # ファイルの拡張子決定
        if(content.tag_name == 'img'):
            file_type = "jpg"
        elif(content.tag_name == 'video'):
            file_type = "mp4"

        # 画像/動画を保存
        with open(f'temporary/content_{ind}.{file_type}', "wb") as f:
            f.write(response)

    except:
        function = sys._getframe().f_code.co_name
        message = '画像・動画ファイルの保存に失敗しました。'
        es.notice_error(module, function, message)
コード例 #4
0
def al_release_follow(driver, profile_url, release_min, release_follow):
    # profile_url:プロフィールのURL
    # release_min:これ以下のフォロー数だと、解除しない
    # release_follow:フォローの解除数

    try:
        # プロフィールに遷移(1回で移動できない時があるから、2回移動)
        for i in range(2):
            driver.get(profile_url)
            es.wait()

        # フォロー数取得
        follows = get_follow(driver)

        # フォロー解除するかどうかの判別
        if(follows > release_min):

            # フォロー中のリスト表示
            display_follow(driver)

            # 一番下までスクロール
            selector = 'body > div.RnEpo.Yx5HN > div > div > div.isgrP' # スクロールする要素のCSSセレクター
            item_xpath = [ # 取り得るXpath
                '/html/body/div[5]/div/div/div[2]/ul/div/li[1]/div',
                '/html/body/div[4]/div/div/div[2]/ul/div/li[1]/div'
            ]
            scroll_item = es.get_elm_by_xpaths(driver, item_xpath) # スクロールする要素
            scroll_height = scroll_item.size['height'] # 一回分のスクロール量取得
            for i in range(follows): # スクロール
                es.scroll(driver, selector, scroll_height)
                es.wait(0.1, 0.1)

            # フォロー解除ボタンの要素を取得
            xpaths = [
                '/html/body/div[4]/div/div/div[2]/ul/div/li/div/div[2]/button',
                '/html/body/div[5]/div/div/div[2]/ul/div/li/div/div[2]/button'
            ]
            elms = es.get_elms_by_xpaths(driver, xpaths)

            # フォロー解除のループ
            for i, elm in enumerate(reversed(elms)):

                # 解除数に到達したらループ終了
                if(i >= release_follow):
                    break

                elm.click() # フォロー中ボタンクリック
                es.wait(1)

                # フォローをやめるボタンをクリック
                release_xpaths = [
                    '/html/body/div[5]/div/div/div/div[3]/button[1]',
                    '/html/body/div[6]/div/div/div/div[3]/button[1]'
                    
                ]
                release_elm = es.get_elm_by_xpaths(driver, release_xpaths)
                release_elm.click()
                es.wait(1)

    # エラー時の動作
    except:
        function = sys._getframe().f_code.co_name
        message = 'フォロー解除中にエラーが起きました。'
        es.notice_error(module, function, message)