5

I'm getting the following message when I run:

instapy: "Invalid Like Element!"

My code is

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()

I think the problem is in xpath_compile.py from InstaPy. At this moment my xpath_compile is set like:

`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']",
}`

Here the error obtained

Any ideas?

Richard
  • 65
  • 6

3 Answers3

7

in /usr/local/lib/python3.6/site-packages/instapy/xpath_compile.py replace xpath["like_image"] section with:

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']",
}
Padi
  • 711
  • 9
  • 18
2

Instagram updated their HTML again as of July 28th, 2020. The correct X-Path should be:

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']",
}
Aaron Ge
  • 21
  • 1
1

Looks Instagram has modified the html.

In the xpath_compile.py file replace xpath["like_image"]

Remove:

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

Replace with:

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']",
}
JavierG
  • 41
  • 2
  • 5