質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Instagram API

Instagram APIは、写真共有SNSであるInstagramの投稿写真をWebサイトに掲載するためのAPIです。取得することでWebサイトと連携し、自動的に投稿写真を表示することができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

1962閲覧

instagramの自動プログラムのエラーメッセージを修正したい

INOUETAKERU

総合スコア0

Instagram API

Instagram APIは、写真共有SNSであるInstagramの投稿写真をWebサイトに掲載するためのAPIです。取得することでWebサイトと連携し、自動的に投稿写真を表示することができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/09/15 02:04

前提・実現したいこと

instgramで自動いいねプログラムをコピーして使用しています。
プログラミング知識は浅く、調べながら動作させることはできました。
4ヶ月程度使用しているんですが、昨日急に下記のエラーが出ました。

どのように修正すればいいのでしょうか。

発生している問題・エラーメッセージ

Traceback (most recent call last):
File "script.py", line 101, in <module>
clicknice()
File "script.py", line 38, in clicknice
target = driver.find_elements_by_class_name('_9AhH0')[10]
IndexError: list index out of range

使用しているコード

### from selenium import webdriver from selenium.common.exceptions import WebDriverException from selenium.webdriver.common.action_chains import ActionChains import time import random def login(): driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher') f = open('insta.txt','a') f.write("instagramにアクセスしました\n") f.close() time.sleep(1) #メアドと、パスワードを入力 driver.find_element_by_name('username').send_keys('ID') time.sleep(1) driver.find_element_by_name('password').send_keys('パスワード') time.sleep(1) #ログインボタンを押す driver.find_element_by_class_name('L3NKy ').click() time.sleep(random.randint(2, 5)) f = open('insta.txt','a') f.write("instagramにログインしました\n") f.close() time.sleep(1) def tagsearch(tag): instaurl = 'https://www.instagram.com/explore/tags/' driver.get(instaurl + tag) time.sleep(random.randint(2, 10)) f = open('insta.txt','a') f.write("listtagより、tagで検索を行いました\n") f.close() time.sleep(1) def clicknice(): target = driver.find_elements_by_class_name('_9AhH0')[10] actions = ActionChains(driver) actions.move_to_element(target) actions.perform() f = open('insta.txt','a') f.write("最新の投稿まで画面を移動しました\n") f.close() time.sleep(1) try: driver.find_elements_by_class_name('_9AhH0')[9].click() time.sleep(random.randint(2, 10)) f = open('insta.txt','a') f.write("投稿をクリックしました\n") f.close() time.sleep(1) driver.find_element_by_class_name('fr66n').click() f = open('insta.txt','a') f.write("投稿をいいねしました\n") f.close() time.sleep(1) except WebDriverException: f = open('insta.txt','a') f.write("エラーが発生しました\n") f.close() return for i in range(random.randint(3, 5)): try: driver.find_element_by_class_name('coreSpriteRightPaginationArrow').click() f = open('insta.txt','a') f.write("次の投稿へ移動しました\n") f.close() time.sleep(random.randint(random.randint(2, 5), random.randint(10, 15))) except WebDriverException: f = open('insta.txt','a') f.write("2つ目の位置でエラーが発生しました\n") f.close() time.sleep(5) try: driver.find_element_by_class_name('fr66n').click() f = open('insta.txt','a') f.write("投稿をいいねしました\n") f.close() time.sleep(2) except WebDriverException: f = open('insta.txt','a') f.write("3acつ目の位置でエラーが発生しました\n") f.close() if __name__ == '__main__': taglist = ['tag', 'tag','tag', 'tag','tag', 'tag', 'tag'] while True: driver = webdriver.Chrome('/Users/takeru/chromedriver/chromedriver') time.sleep(1) login() tagsearch(random.choice(taglist)) clicknice() driver.close() abc = random.randint(random.randint(20, 100), random.randint(120, 1800)) f = open('insta.txt','a') f.write(str(abc)+"秒待機します\n") f.close() time.sleep(abc)

補足情報(FW/ツールのバージョンなど)

昨日14日までは動作していました。aa
ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

IndexError: list index out of range

配列またはリストの要素数を超えてアクセスしようとした場合に出るエラーです

target = driver.find_elements_by_class_name('_9AhH0')[10]

driver.find_elements_by_class_name('_9AhH0')
の要素数はいくらか調べてみては

投稿2020/09/15 02:10

y_waiwai

総合スコア87802

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

INOUETAKERU

2020/09/16 02:58

回答ありがとうございます。 要素数はどのように調べるのでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問