Skip to content

Instantly share code, notes, and snippets.

@adaRn
Created September 12, 2019 05:50
Show Gist options
  • Save adaRn/543281afc32ac3dbb2dab934a08df863 to your computer and use it in GitHub Desktop.
Save adaRn/543281afc32ac3dbb2dab934a08df863 to your computer and use it in GitHub Desktop.
crawl facebook fanpage images
require 'nokogiri'
require 'open-uri'
require 'uri'
# url = 'https://www.facebook.com/LifeFitness'
# for fanpages with videocover, it won't find the cover
url = 'https://www.facebook.com/cleverfit.dornach'
fb_website = open(url, 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36').read
profile_picture = Nokogiri::HTML.parse(fb_website).search('[itemprop="image"]').first['src']
profile_picture_correctly_found = (profile_picture =~ URI::regexp) == 0
cover_photo = fb_website.split('"cover_photo"').last.split('"uri":')[1].split('},"is').first[1..-2].gsub('\/', '/')
cover_photo_correctly_found = (cover_photo =~ URI::regexp) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment