Instapy: like element has changed

Created on 25 Oct 2018  路  40Comments  路  Source: timgrossmann/InstaPy

any fix ?

help wanted wontfix

Most helpful comment

Possible Changes

like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"

in like_util.py

@sionking could this work instead?

All 40 comments

like_xpath = "//button/span[@aria-label='Like']" now return also comments like element so need to find different logic

yeah im getting this error all time:

Image was not able to get Liked! maybe blocked ?

any fix?

Tried the newest update and it works again.

Tried the newest update and it works again.

sure? because its doesnt work for me

Hi there,

Same problem here but it seems intermittent. See below:

Logs

INFO [2018-10-25 00:12:25] [xxx] Post [1/2]
INFO [2018-10-25 00:12:25] [xxx] https://www.instagram.com/p/BpVP5WEFh38/?taken-by=moox_officiel
INFO [2018-10-25 00:12:28] [xxx] Image from: b'moox_officiel'
INFO [2018-10-25 00:12:28] [xxx] Link: b'https://www.instagram.com/p/BpVP5WEFh38/?taken-by=moox_officiel'
INFO [2018-10-25 00:12:28] [xxx] Description: b'#moox1_said #naturegram #naturelove #natureporn #wilderness #nature_seekers #naturelovers #keepitwild #adventure #instapassport #instatraveling #discoverearth #nature_obsession #backpacking #neverstopexploring\xc2\xa0 #exploreeverything #landscape_captures #travellingthroughtheworld #instatravel #landscapephotography\xc2\xa0 #landscapehunter #folk #glacier #wildlife #planetearth #earthfocus'
INFO [2018-10-25 00:12:30] [xxx] --> Image Liked!
INFO [2018-10-25 00:12:33] [xxx] --> Not commented
INFO [2018-10-25 00:12:35] [xxx] Post [2/2]
INFO [2018-10-25 00:12:35] [xxx] https://www.instagram.com/p/BpVEgqDFOLE/?taken-by=moox_officiel
INFO [2018-10-25 00:12:38] [xxx] Image from: b'moox_officiel'
INFO [2018-10-25 00:12:38] [xxx] Link: b'https://www.instagram.com/p/BpVEgqDFOLE/?taken-by=moox_officiel'
INFO [2018-10-25 00:12:38] [xxx] Description: b'#moox1_said #naturegram #naturelove #natureporn #wilderness #nature_seekers #naturelovers #keepitwild #adventure #instapassport #instatraveling #discoverearth #nature_obsession #backpacking #neverstopexploring\xc2\xa0 #exploreeverything #landscape_captures #travellingthroughtheworld #instatravel #landscapephotography\xc2\xa0 #landscapehunter #folk #glacier #wildlife #planetearth #earthfocus'
INFO [2018-10-25 00:14:18] [xxx] --> Invalid Like Element!

Possible solution

Use the common part of the class (glyphsSpriteHeart) instead of aria-label for Like button:

span class="glyphsSpriteHeart__outline__24__grey_9 u-__7" aria-label="Like">

While checking my log I see most images were liked and some are invalid:

INFO [2018-10-25 10:06:56] User: XXX >> followers: 457 | following: 753 | relationship ratio: 0.61
INFO [2018-10-25 10:07:03] [] --> Image Liked!
INFO [2018-10-25 10:07:07] [] [3/10]

INFO [2018-10-25 10:07:39] User: XXX >> followers: 1923 | following: unknown | relationship ratio: unknown
INFO [2018-10-25 10:08:10] [] --> Invalid Like Element!
INFO [2018-10-25 10:08:10] [] [5/10]

So my message about everything works again was not right. Some elements are not working. How is that even possible??

like_xpath = "//button/span[@aria-label='Like']" now return also comments like element so need to find different logic

@sionking is the button function name same? if yes possible to xpath a fix name for it?

**<section class="ltpMr Slqrh">
        <span class="fr66n">
                <button class="coreSpriteHeartOpen oF4XW dCJp8">
                           **<span class="glyphsSpriteHeart__outline__24__grey_9 u-__7" aria-label="Like"**</span>**                 
                </button>
          </span>
        <span class="_15y0l">
                <button class="oF4XW dCJp8">
                           <span class="glyphsSpriteComment__outline__24__grey_9 u-__7" aria-label="Comment"/>
                </button></span>
         <span class="_5e4p">
                <button class="oF4XW dCJp8">
                            <span class="glyphsSpriteShare__outline__24__grey_9 u-__7" aria-label="Share Post"/>
                </button>
          </span>
        <span class="wmtNn">
                  <button class="oF4XW dCJp8">
                             <span class="glyphsSpriteSave__outline__24__grey_9 u-__7" aria-label="Save"/>
                 </button>
           </span>
</section>

Not sure if the button class name is browser specific but as for the comment like button it will be 
        <span class="jdtwu">
                <button class="_2ic5v">
                           **<span class="glyphSpriteComment_like u-__7" aria-label="Like"</span>**                
                </button>'

vs
**

@JoeFertig means the error still there "Invalid Like Element" is the issue and like @sionking said comment like button and picture like button now has the same shared xpath

hm... I have same error but not always maybe 8 times out of 10

Invalid Like Element!

Possible Changes

like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"

in like_util.py

@sionking could this work instead?

same issue here "Invalid Like Element!"

like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"`

seems like a good solution!

same problem

@fabian-pandas Thanks, looks like it works for me.

same problem

Possible Changes
like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"

in like_util.py
@sionking could this work instead?

I have same error but not Always, maybe 7/8 times out of 10.
I modified and saved the change on the script like_util.py as described above while I was running a quickstart-template.
Is the change activated immediately or the next time the template is run?

Thanks!

Possible Changes

like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"

in like_util.py

@sionking could this work instead?

This work for me 25/10/18 馃憤

This fix works for me as well, on 2 different accounts.

I just changed the condition from len(like_elme) == 1 to > 1
There are some cases that can fail but most will work.
I wtill try what suggested here, please PR.

@sionking I wanted to PR but I have no access from @timgrossmann (Error 403)
Or is there any way that I can request access?

I tried this:

like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"

and this:
len(like_elem) > 1

but nothing works for me. Always "invalid like element".

Worked for me!

I had to change the variables

like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"`

on the file /instapy/like_util.py
and now it looks great!

Possible Changes

like_xpath = "//button/span[@class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"

in like_util.py

@sionking could this work instead?

Worked for me also

After i have changed like_xpath and unlike_xpath i get this error:
Traceback (most recent call last): File "senzatempo_gelateriapiadineriabck/quickstart.py", line 3, in <module> from instapy import InstaPy File "/insta/senzatempo_gelateriapiadineriabck/instapy/__init__.py", line 2, in <module> from .instapy import InstaPy File "/insta/senzatempo_gelateriapiadineriabck/instapy/instapy.py", line 26, in <module> from .like_util import check_link File "/insta/senzatempo_gelateriapiadineriabck/instapy/like_util.py", line 16, in <module> from .util import web_adress_navigator ImportError: cannot import name web_adress_navigator

I tried this:

like_xpath = "//button/span[@Class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@Class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"

and this:
len(like_elem) > 1

but nothing works for me. Always "invalid like element".

This isn't a perfect soloution, uploading a better one in a few minutes.

I tried this:
like_xpath = "//button/span[@Class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@Class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"
and this:
len(like_elem) > 1
but nothing works for me. Always "invalid like element".

This works for me too, we should PR and merge it to master.

At which line you modify len(like_elem) > 1?

I tried this:
like_xpath = "//button/span[@Class='glyphsSpriteHeart__outline__24__grey_9 u-__7' and @aria-label='Like']"
unlike_xpath = "//button/span[@Class='glyphsSpriteHeart__filled__24__red_5 u-__7' and @aria-label='Unlike']"
and this:
len(like_elem) > 1
but nothing works for me. Always "invalid like element".

This works for me too, we should PR and merge it to master.

At which line you modify len(like_elem) > 1?

at line 567 :)

Have added the two changes and still get the error

Have added the two changes and still get the error

Me too. I'm trying to debug it myself. I keep you posted!

The xpath looks correct. I am also a bit stumped

Does anyone did make a PR?

These are the proper xpath's for the like and unlike button:
like_xpath = '//[@class="coreSpriteHeartOpen oF4XW dCJp8"]//[@aria-label="Like"]'
unlike_xpath = '//[@class="coreSpriteHeartOpen oF4XW dCJp8"]//[@aria-label="Unlike"]'

And you should change this back too if you already tried the changes suggested here:
len(like_elme) == 1

This error occurred because whoever wrote the base code didn't make the selector\xpath unique enough and now that IG has added the like for comments feature the bot found more than one option and didn't know how to deal with it.

Now that the comment liking option is added another interesting option could be to add this:
def like_image_comments(browser, logger):
"""Likes the image's comments in the opened browser"""
# check action availability
if quota_supervisor("likes") == "jump":
return False, "jumped"

comment_like_xpath = '//*[@class="glyphsSpriteComment_like u-__7"]'
comment_unlike_xpath = '//*[@class="glyphsSpriteComment_like_active u-__7"]'

# find like comment elements
comment_like_elem = browser.find_elements_by_xpath(comment_like_xpath)
comments_unlike_elem = browser.find_elements_by_xpath(comment_unlike_xpath)
comment_counter = len(comments_unlike_elem)
if len(comment_like_elem) >= 1:
    # sleep real quick right before clicking the elements
    sleep(2)
    for like in comment_like_elem:
        sleep(1)
        click_element(browser, like)
        comment_counter += 1
        # check now we have unlike instead of like
        if comment_counter == len(browser.find_elements_by_xpath(comment_unlike_xpath)):
            logger.info('--> Comment Liked!')
        else:
            logger.info('--> Comment not Liked! Maybe blocked?')
            sleep(120)


else:
    if len(comments_unlike_elem) >= 1:
        logger.info('--> Image comments already liked!')
        return False

logger.info('--> Invalid comment Like Element!')

I know it's not perfect and need to be added to the quota and to the activities but this could be a nice base.
I don't have permissions to create a pull request I belive so someone please add it. @uluQulu @sionking

@nimrodlavi your xpaths didn't work for me but the reasoning did and I found these to work

like_xpath = "//button[contains(@class, 'coreSpriteHeartOpen oF4XW dCJp8')]/span[contains(@aria-label,'Like')]"
unlike_xpath = "//button[contains(@class, 'coreSpriteHeartOpen oF4XW dCJp8')]/span[contains(@aria-label,'Unlike')]"

hope they work for others

@nimrodlavi your xpaths didn't work for me but the reasoning did and I found these to work

like_xpath = "//button[contains(@class, 'coreSpriteHeartOpen oF4XW dCJp8')]/span[contains(@aria-label,'Like')]"
unlike_xpath = "//button[contains(@class, 'coreSpriteHeartOpen oF4XW dCJp8')]/span[contains(@aria-label,'Unlike')]"

hope they work for others

Interesting, are you running on linux or win?
And your path's look a lot cleaner, thanks for the share.

@nimrodlavi your xpaths didn't work for me but the reasoning did and I found these to work

like_xpath = "//button[contains(@class, 'coreSpriteHeartOpen oF4XW dCJp8')]/span[contains(@aria-label,'Like')]"
unlike_xpath = "//button[contains(@class, 'coreSpriteHeartOpen oF4XW dCJp8')]/span[contains(@aria-label,'Unlike')]"

hope they work for others

This work for me in Ubuntu Server 18, Thanks!

@nimrodlavi Linux. Probably Ubuntu server 14. I like contains, very human readable. Thanks for the inspiration

Hi there
For the people having Invalid Like Element issue,
I prepared a generic solution at #3260 馃殌


Cheers 馃榿

@nimrodlavi solution didn't work for me
@alxhoff solution worked for me

Running macOX

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Hi, this XPath -> (//span[@aria-label="Like"])[1] is working for my script. Do assign me to this issue. I'll try to fix this.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this problem still occurs, please open a new issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CharlesCCC picture CharlesCCC  路  3Comments

harrypython picture harrypython  路  3Comments

rahulkapoor90 picture rahulkapoor90  路  3Comments

n0sw34r picture n0sw34r  路  3Comments

Naramsim picture Naramsim  路  3Comments