Skip to content

Instantly share code, notes, and snippets.

@quangpham
Created May 6, 2018 23:19
Show Gist options
  • Save quangpham/aba945daa4c1f5ca557e98d33e2b1d43 to your computer and use it in GitHub Desktop.
Save quangpham/aba945daa4c1f5ca557e98d33e2b1d43 to your computer and use it in GitHub Desktop.
users = []
["stephencurry30","kevindurant","ygtrece"].each do |fan|
driver.get "https://www.instagram.com/#{fan}"
sleep(20)
hrefs = []
driver.find_elements(:css => "a._ndl3t").each {|a| hrefs.push a["href"]}
hrefs.each_with_index do |href, index|
puts "#{index} / #{hrefs.count}"
driver.get href
sleep(1)
ig_user = "#{href.gsub("https://www.instagram.com/","").gsub("/","")}"
posts = driver.find_elements(:css => "span._fd86t")[0].text
puts posts
followers = driver.find_elements(:css => "span._fd86t")[1].text
if followers.index(",")
_followers = followers.gsub(",","").to_f
elsif followers.index("k")
_followers = followers.gsub("k","").to_f*1000
elsif followers.index("m")
_followers = followers.gsub("k","").to_f*1000000
else
_followers = 0
end
puts "#{followers} | #{_followers}"
number_of_following = driver.find_elements(:css => "span._fd86t")[2].text
puts number_of_following
link = nil
if a = driver.find_elements(:css => "a._ng0lj").first
link = a.text
end
object = {
fan: fan,
user: ig_user,
followers: _followers,
following: number_of_following,
link: link,
posts: posts
}
users.push object
driver.save_screenshot("_ss/#{ig_user}.png")
end
end
users.each do |u|
if File.exist?("_ss/#{u[:"user"]}.png")
users2.push(u)
puts "#{u[:"fan"]}|#{u[:"user"]}|#{u[:"followers"]}|#{u[:"following"]}|#{u[:"posts"]}|#{u[:"link"]}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment