Ever wanted to like all the posts of your friends or family on
Instagram without actually doing it by yourself ?
well here is the solution :)
Everything on web is an HTML element, and can be targeted by using its class or id.
On Instagram web as well you can target the post of a user by using the element's class (i.e _9AhH0 in this case).
Now once the post is opened you can target the like button and fire click() event on it.
And that's it...
Note: The account should be public or you should be following the user
Few Engineering stuff
- In order to pull the post, Instagram hit a 'query' API and loads it.
Now as this is an API call it takes some time to respond (i.e. our watchTime in following code).
Loading time depends on various factor like how scalable the end server is ?, what is your current internet speed ? ect.
This is important because you can not target something which is not there. Therefore, the post must be loaded before
moving to further step.
- Now, once you click the like button, Instagram again makes an API call which preform write/update
action on the database. This is an expensive API call and if allowed to be hit rigorously without any caution, it may result in DDoS attack.
Therefore, to avoid this we generally use rate-Limiting logic (Note: I don't know what instagram is actually using for rate limiting,
if you are interested further, you can search about AWS WAF & cloudFront).
If you continuously try to hit the like API, it will start throwing 429(Too Many Requests response) error code.
To avoid this we can put sleep() in between the API calls, and it should avoid the rate-limiting
(Note: it does not mean that this should always work on every web app, but at the time this post is being written it works on instagram)
???
- Class name
_9AhH0
does not look like human named.
therefore, these attribute may be added at the time of build and maybe changed if instagram push a new release.
If this is the case, then you have to find the new className and change your code, PS I will try to update the blog but no promises.
How to Use
- Open Instagram on web.
- Go to your friend's profile or use mine.
- Open console - click me if you need help in this
- Copy the following
code
and paste it in the console and hit enter.
- Change the
totalPost
value according to the no. of posts you want to like or to total no. of post user have.
- Change the
minWatchTime
value according to your internet speed (3000 = 3 sec)