Skip to content

Instantly share code, notes, and snippets.

@stevemcquaid
Forked from unp/fb_profile_extractor.rb
Created January 23, 2019 02:17
Show Gist options
  • Save stevemcquaid/7ae1131cd9bb5f03d5f0de5b7d394013 to your computer and use it in GitHub Desktop.
Save stevemcquaid/7ae1131cd9bb5f03d5f0de5b7d394013 to your computer and use it in GitHub Desktop.
Extracts user names and profile URLs from Facebook group members' page
require 'nokogiri'
require 'csv'
doc = File.open("members.htm") do |f|
html = Nokogiri.HTML(f)
CSV.open("users.csv", "w") do |csv|
csv << ['Name', 'Profile Link']
users = html.css('.uiProfileBlockContent').map do |profile_block|
link = profile_block.css('a').first['href'].match(/(https:\/\/www.facebook.com\/.*)\?/)[1]
name = profile_block.css('a').first.text.strip
[name, link]
end
users.uniq.map { |u| csv << u }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment