-
-
Save Fercell/e93e24dd6445c793513f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rubygems" | |
require "selenium-webdriver" | |
require "dotenv" | |
Dotenv.load | |
@driver = Selenium::WebDriver.for :firefox | |
@driver.manage.timeouts.implicit_wait = 10 | |
@driver.navigate.to "instagram.com" | |
def login | |
@driver.find_element(:name, "username").send_keys(ENV["INSTAGRAM_USERNAME"]) | |
@driver.find_element(:name, "password").send_keys(ENV["INSTAGRAM_PASSWORD"]) | |
@driver.find_element(:xpath, "//button").click | |
end | |
def things_to_like | |
@driver.find_elements(:partial_link_text, "Like") | |
end | |
def scroll_to_autoload | |
load_more_button = @driver.find_elements(:css, ".-cx-PRIVATE-AutoloadingPostsGrid__moreLink") | |
load_more_button.first.click if load_more_button.any? | |
@driver.execute_script("window.scrollTo(0,document.body.scrollHeight);") | |
@driver.execute_script("window.scrollTo(0,0);") | |
@driver.execute_script("window.scrollTo(0,document.body.scrollHeight);") | |
end | |
login | |
count = 0 | |
already_liked_pages = 0 | |
current_time = Time.now | |
while current_time + 300 < Time.now || already_liked_pages <= 3 | |
if things_to_like.any? | |
things_to_like.each do |l| | |
l.click | |
count += 1 | |
end | |
else | |
already_liked_pages += 1 | |
end | |
scroll_to_autoload | |
sleep(3) | |
end | |
open('instagram.log', 'a') do |f| | |
f.puts "#{Time.now} : You liked #{count} things." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment