Sha256: 1efa763fc66dcb4a8a9efdda3753c4d3450265d8a3df7a8f36d3e5f1b56a808a
Contents?: true
Size: 779 Bytes
Versions: 2
Compression:
Stored size: 779 Bytes
Contents
module PictureFrom module Crawlers class FacebookCrawler def image_url_by_user_info(user_info) page = SearchPage.new(user_info) page.usernames.first end class SearchPage < BaseCrawler::Page def initialize(user_info) @page = open_url("https://www.facebook.com/search.php?q=#{user_info}") end def usernames results.map { |result| username_from_url(result['href']) }.compact end private def username_from_url(url) match = %r{^https?://(www\.)?facebook.com/(?<u>[^/\.]*)/?$}.match(url) match[:u] if match end def results @page.css('#pagelet_search_results .instant_search_title a') end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
picture_from-1.0.1 | lib/picture_from/crawlers/facebook_crawler.rb |
picture_from-1.0.0 | lib/picture_from/crawlers/facebook_crawler.rb |