Skip to content

Instantly share code, notes, and snippets.

@unp
Created January 23, 2019 02:17
Show Gist options
  • Save unp/576be75958f257dca1a4ec35225121c9 to your computer and use it in GitHub Desktop.
Save unp/576be75958f257dca1a4ec35225121c9 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