-
-
Save stevemcquaid/7ae1131cd9bb5f03d5f0de5b7d394013 to your computer and use it in GitHub Desktop.
Extracts user names and profile URLs from Facebook group members' page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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