instaloader - 验证登录以确保使用 python 模块登录

问题描述 投票:0回答:3

我正在使用 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 的会话文件,所以我不确定为什么会话文件不起作用,但这让我更多地思考我最初担心登录不起作用是真的。

如何调试/确认登录是否正常?

python instagram instagram-api
3个回答
1
投票

错误指的是

L.load_session_from_file(testuser)
,您必须将用户名作为字符串传递,所以尝试
L.load_session_from_file("testuser")


1
投票

您需要定义 testuser,因为您已将其作为变量传递,要修复它,请将其打包在里面:

"testuser"

希望能解决您的问题。


0
投票

仅在命令行上,下面没有 (),仅供参考。 instaloader (个人资料) --login just_scrolling_p --sessionfile 会话-(文件名) --stories --no-profile-pic --no-posts --no-videos

错误:从 c:\users\Darth ppdata\local emp/.instaloader-darth/session-(profile) 加载会话。 对 graphql/query 的 JSON 查询:HTTP 错误代码 401。[重试;用 ^C 跳过] 对 graphql/query 的 JSON 查询:HTTP 错误代码 401。[重试;用 ^C 跳过] 致命错误:对 graphql/query 的 JSON 查询:HTTP 错误代码 401。

© www.soinside.com 2019 - 2024. All rights reserved.