我正在使用instaloader收集一些关于我的instagram账户的数据。
我写了一个非常基本的循环来获得我的追随者,它工作得很好:
# Get instance
import instaloader
L = instaloader.Instaloader()
# Login or load session
L.login("myuser", "mypass") # (login)
#L.load_session_from_file(myaccount)
# Obtain profile metadata
profile = instaloader.Profile.from_username(L.context, "testaccount")
# Print list of followees
follow_list = []
count=0
file = open("output.txt","a+")
for followee in profile.get_followers():
username = followee.username , followee.external_url
file.write(username + "\n")
print(username)
file.close()我随机尝试了一个更大的账号,上面有大约2000个关注者,只是想看看它在我的测试账号上的表现,我的测试账号有10个关注者,以保持简单。
我得到了一个错误
Requests within last 10/11/20/22/30/60 minutes grouped by type:
* other: 1 1 1 1 1 1
Instagram responded with HTTP error "429 - Too Many Requests". Please
do not run multiple instances of Instaloader in parallel or within
short sequence. Also, do not use any Instagram App while Instaloader
is running.
The request will be retried in 666 seconds, at 09:18.我在instaloader的常见问题和故障排除部分看到了这一点,它似乎表明,如果你没有登录,这种情况更常见,所以我开始怀疑我的登录是否真的有效。
我使用命令行界面创建了一个会话文件
instaloader -login testuser它工作并创建了一个会话文件
dev@cab:~/test2 $ ls -la ~/.config/instaloader/session-testuser 我更新了示例代码
# Get instance
import instaloader
L = instaloader.Instaloader()
# Login or load session
#L.login("myuser", "mypass") # (login)
L.load_session_from_file(testuser)
# Obtain profile metadata
profile = instaloader.Profile.from_username(L.context, "testaccount")
# Print list of followees
follow_list = []
count=0
file = open("output.txt","a+")
for followee in profile.get_followers():
username = followee.username , followee.external_url
file.write(username + "\n")
print(username)
file.close()但是,当我随后尝试这个脚本时,我得到了错误
Traceback (most recent call last):
File "gram2.py", line 7, in <module>
L.load_session_from_file(testuser)
NameError: name 'testuser' is not defined从我所读到的,但在文档上不能确定,但我在网上做了一些很好的例子,我不需要指定会话文件的路径,只需要用户名,它应该自动在$user/.conf/instaloader中查找会话文件,所以我不确定会话文件为什么不工作,但这让我更多地思考我最初担心的登录不工作是真的。
如何调试/确认登录是否正常?
发布于 2021-05-08 22:26:28
该错误涉及L.load_session_from_file(testuser),您必须以字符串形式传递用户名,因此尝试使用L.load_session_from_file("testuser")
发布于 2021-08-06 18:46:31
您需要定义testuser,因为您已经将其作为变量传递,以修复它,并将其打包到:"testuser"中。
希望这能解决你的问题。
https://stackoverflow.com/questions/64855393
复制相似问题