I made my own Instagram automatic like tool [Ruby]

Introduction

I want to increase my Instagram followers. But I don't want to spend so much time. Paid Instagram tools seem to be expensive,

That's why I created a programming that can automatically like it!

Target person

Environment when I developed

version 
Ruby 2.6.3
gem 3.0.3
Homebrew 2.5.2 

Development procedure

First, install selenium-driver.

selenium is a browser automation tool. You can operate the browser automatically. Based on a script written in Ruby, Pyhon, etc., JavaScript for operating the browser is generated, and the JavaScript is embedded in the target page to operate the browser.

Reference article https://app.codegrid.net/entry/selenium-1

Install selenium-driver

gem install selenium-webdriver 

Then install chrome-driver. chrome-driver is a driver (software) required to operate Google Chrome. A dedicated driver is prepared for each browser.

Install chrome-driver

brew install chrome-driver

Then pass the chrome-driver path.

$ echo export PATH=' ●●(:$PATH'  >> ~/ .bash_profile

Then implement it.

Whole source

insta_auto.rb


require 'selenium-webdriver'
require 'uri'

class InstagramBot
  attr_accessor :driver
  def initialize(username,password)
    
  end

  def good_hashtag(key_word,number)
   
  end

  def good_user_post(username,number)
   
  end

end
username = ""
password = ""
bot = InstagramBot.new(username,password)
key_word = ""
bot.good_hashtag(key_word,15)
# username = ""
# bot.good_user_post(username,15)

Login function

insta_auto.rb


 def initialize(username,password)
    #Abbreviation
    ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36'
    puts "aaaaaaaaaaa"
    caps = Selenium::WebDriver::Remote::Capabilities.chrome('chromeOptions' => { args: ["--user-agent=#{ua}", 'window-size=1280x800', '--incognito'] }) #Secret mode
    puts "vbbbbbbb"
    client = Selenium::WebDriver::Remote::Http::Default.new
    client.read_timeout = 300
    @driver = Selenium::WebDriver.for :chrome, desired_capabilities: caps, http_client: client
    @driver.manage.timeouts.implicit_wait = 30
    @driver.navigate.to'https://www.instagram.com/accounts/login/?source=auth_switcher'
    puts "ddddd"
    @driver.find_element(:name, 'username').send_keys(username)
    @driver.find_element(:name, 'password').send_keys(password)
    sleep 1
    @driver.find_element(:name, 'password').send_keys(:return)
  end

Like the specified hashtag

insta_auto.rb


def good_hashtag(key_word,number)
    encode_word = URI.encode(key_word)
    sleep 3
    @driver.navigate.to"https://www.instagram.com/explore/tags/#{encode_word}/"
    sleep 2
    @driver.execute_script("document.querySelectorAll('article img')[9].click()")
    sleep 2
    number.times{
      begin
        @driver.execute_script("console.log(document.querySelectorAll('button.wpO6b')[1].click())")
        sleep 2
      rescue
        puts "already good this post"
      end
      sleep 2
      @driver.execute_script("document.querySelector('a.coreSpriteRightPaginationArrow').click()")
      sleep 2
    }
  end

Add a hashtag to the specified user

insta_auto.rb


def good_user_post(username,number)
    sleep 3
    @driver.navigate.to"https://www.instagram.com/#{username}/"
    sleep 2
    @driver.execute_script("document.querySelectorAll('article img')[0].click()")
    sleep 2
    number.times{
      begin
        @driver.execute_script("document.querySelectorAll('span.glyphsSpriteHeart__outline__24__grey_9')[1].click()")
      rescue
        puts "already good this post"
      end
      sleep 2
      @driver.execute_script("document.querySelector('a.coreSpriteRightPaginationArrow').click()")
      sleep 2
    }
  end

Summary

It took a long time to build the development environment. On the other hand, there were many articles that could be helpful in writing the source code, so I didn't have much trouble and was saved. As for my skin feeling, I think that many programming beginners say, "I'm studying a language to some extent, but when it comes to building an environment, I gradually enter the field." For me who just graduated from programming school, it was quite difficult to build an environment from scratch lol Because I have to go through quite a lot of articles and make trial and error. So this time, I made an "article that systematizes a series of flows" for people like me! I'm glad if you can use it as a reference.

Also, it is rumored that if you use this Instagram automatic like function too much, your account may be deleted from Instagram. Please use it at your own risk!

Reference article:

https://qiita.com/nirs_kd56/items/6979a026497f2f4a59bf https://qiita.com/FJHoshi/items/c847ad51af388d2dbb4a https://qiita.com/y-agatsuma/items/ea2c9845ee0a931d5c9c

Recommended Posts

I made my own Instagram automatic like tool [Ruby]
I updated my own blackjack made with Ruby for my portfolio
Ruby: I made a FizzBuzz program!
I made a package.xml generation tool.
I made my own PC for deep learning. (Windows10, Ubuntu18.04 dual boot)
[Ruby] I made a simple Ping client
I made various Fibonacci sequence functions (Ruby)
I made a risky die with Ruby
I made a new Java deployment tool
I made a Diff tool for Java files
I made blackjack with Ruby (I tried using minitest)
I made a Ruby extension library in C
I made a portfolio with Ruby On Rails