Sha256: 107589f7d9ea0ddf2cc1e7ddab8eec557d5757bb6e9182cf4ba7275e1fb52408
Contents?: true
Size: 706 Bytes
Versions: 1
Compression:
Stored size: 706 Bytes
Contents
require 'open-uri' require 'nokogiri' module PictureFrom module Crawlers class FacebookCrawler def query(keyword) page = search_page(keyword) results = page.css('#pagelet_search_results .instant_search_title a') username_from_url(results.first['href']) if results.size > 0 end private def search_page(query) search_page_url = "https://www.facebook.com/search.php?q=#{query}" Nokogiri::HTML open(search_page_url) end def username_from_url(url) url_regex = %r{^https?://(www\.)?facebook.com/(?<username>[^/\.]*)} match = url_regex.match(url) match[:username] if match end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
picture_from-0.0.1 | lib/picture_from/crawlers/facebook_crawler.rb |