5

我在运行时收到以下消息:

instapy: "Invalid Like Element!"

我的代码是

from instapy import InstaPy

insta_username = 'username'
insta_password = 'password'


session = InstaPy(username=insta_username, password=insta_password)
session.login()

session.set_delimit_commenting(enabled=True, max_comments=50000, min_comments=0)
session.set_do_comment(enabled=True, percentage=50)
session.set_comments(['comment1', 'comment2'])

session.like_by_tags(['tag1','tag2'], amount=40)



session.end()

我认为问题出在 InstaPy 的 xpath_compile.py 中。此时我的 xpath_compile 设置为:

`xpath["like_image"] = {
    "like": "/html/body/div[1]/section/main/div/div/article/div[3]/section[1]/span[1]/button[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "/html/body/div[1]/section/main/div/div/article/div[3]/section[1]/span[1]/button[*[local-name()='svg']/@aria-label='Unlike']",
}`

这里得到的错误

有任何想法吗?

4

3 回答 3

7

在 /usr/local/lib/python3.6/site-packages/instapy/xpath_compile.py 将 xpath["like_image"] 部分替换为:

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}
于 2020-07-16T17:01:35.827 回答
2

自 2020 年 7 月 28 日起,Instagram 再次更新了他们的 HTML。正确的 X-Path 应该是:

xpath["like_image"] = {
    "like": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div/span[*[local-name()='svg']/@aria-label='Unlike']",
}
于 2020-07-28T18:37:42.010 回答
1

看起来 Instagram 已经修改了 html。

在 xpath_compile.py 文件中替换 xpath["like_image"]

消除:

xpath["like_image"] = {
    "like": "//section/span/button[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button[*[local-name()='svg']/@aria-label='Unlike']",
}

用。。。来代替:

xpath["like_image"] = {
    "like": "//section/span/button/div[*[local-name()='svg']/@aria-label='Like']",
    "unlike": "//section/span/button/div[*[local-name()='svg']/@aria-label='Unlike']",
}
于 2020-07-21T18:12:27.853 回答