Skip to content

Instantly share code, notes, and snippets.

@johndel
Last active April 25, 2018 06:35
Show Gist options
  • Save johndel/29afec4b159203baf7521cd5a50dbb60 to your computer and use it in GitHub Desktop.
Save johndel/29afec4b159203baf7521cd5a50dbb60 to your computer and use it in GitHub Desktop.
require 'mechanize'
fb_friends = []
# login
agent = Mechanize.new
page = agent.get("https://www.facebook.com")
next_page = page.form_with(:id => 'login_form') do |form|
form.field_with(:id => 'email').value = 'username'
form.field_with(:id => 'pass').value = 'password'
end.submit
i = 0
while true do
page2 = agent.get("https://touch.facebook.com/profile.php?v=friends&startindex=#{i}")
if page2.search("h3 a").count != 0
page2.search("h3 a").each do |link|
fb_friends << link.children.first.text
end
i = i + page2.search("h3 a").count
else
break
end
end
fb_friends = fb_friends.uniq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment