Skip to content

Instantly share code, notes, and snippets.

@AlJohri
Created August 25, 2013 07:08
Show Gist options
  • Save AlJohri/6332427 to your computer and use it in GitHub Desktop.
Save AlJohri/6332427 to your computer and use it in GitHub Desktop.
Scrape closed facebook group
#!/usr/bin/env ruby
require 'mechanize'
require 'json'
@agent = Mechanize.new{|a| a.user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'}
@agent.get 'https://m.facebook.com/'
# 'Log In'
form = @agent.page.form_with(:method => 'POST')
form['email'], form['pass'] = ARGV[0], ARGV[1]
@agent.submit(form, form.buttons[0])
# 'Continue'
form = @agent.page.form_with(:method => 'POST')
@agent.submit(form, form.buttons[0])
# 'This is Okay'
form = @agent.page.form_with(:method => 'POST')
@agent.submit(form, form.buttons[1])
# 'Do Not Save Device'
if (@agent.page.uri.to_s.match('home.php').nil?)
form = @agent.page.form_with(:method => 'POST')
form.radiobuttons[1].check
@agent.submit(form, form.buttons[0])
end
counter = 0
(1..1863).step(91).each { |x|
page = @agent.get("https://www.facebook.com/ajax/browser/list/group_members/?id=544437542236500&gid=544437542236500&edge=groups%3Amembers&order=default&view=list&start=#{x}&__a=1")
json = JSON.parse(page.body[9..-1])
html = json['domops'][0][3]['__html']
doc = Nokogiri::HTML::parse(html)
doc.search('a').each { |x|
if x.text != "" && x.text != "See More"
counter = counter + 1
puts "-----------------------------------"
puts "#{counter} #{x.text}"
system "./directory.rb -n \"#{x.text}\""
end
}
}
@carlvlewis
Copy link

Hey @AlJohri, does this script still work after FB's API change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment