python
1searchs = tweepy.Cursor(api.user_timeline, q = user_, include_entities = True, tweet_mode = 'extended').items(10) 2print(searchs) 3for search in searchs: 4 #print(json.dumps(search._json, indent=2)) 5 print('~'*30) 6 print(i01) 7 i01 =i01+ 1 8 if hasattr (search,"extended_entities"): 9 for media in search.extended_entities.get("media",[]): 10 media_id = media["id"] 11 img_url = media["media_url"] 12 print(img_url) 13 print(search.id) 14 print('--'*30) 15 16 else: #問題の部分 17 if hasattr (search,'retweeted_status'): 18 for media in search.retweeted_status.get('extended_entities','media',[]): 19 media_id = media["id"] 20 img_url = media["media_url"] 21 print(img_url) 22 print(search.id) 23 print('--'*30) 24
エラー
Traceback (most recent call last):
File "C:\Users\81703\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:\Users\81703\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "c:\Users\81703.vscode\extensions\ms-python.python-2021.2.582707922\pythonFiles\lib\python\debugpy_main.py", line 45, in <module>
cli.main()
File "c:\Users\81703.vscode\extensions\ms-python.python-2021.2.582707922\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\Users\81703.vscode\extensions\ms-python.python-2021.2.582707922\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("main"))
File "C:\Users\81703\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\81703\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\81703\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\81703\Desktop\作業用\自動写真保存機1号改\自動写真保存機1号.py", line 44, in <module>
for media in search.retweeted_status.get('extended_entities','media',[]):
AttributeError: 'Status' object has no attribute 'get'
Twitterの画像を習得するためjsonファイルでURLを確認したところたまにretweeted_statusの中にextended_entitiesがあることがあるのですがこれを取得しようとすると上記のエラーが出てしまいます。何か解決策をご存じの方がいらっしゃいましたら教えていただけますでしょうか。
回答1件
あなたの回答
tips
プレビュー