$ git clone https://github.com/Manbo-/faraday-scraper
$ cd faraday-scraper
$ rake install
require "faraday/scraper"
module Pages
class Links < Faraday::Scraper::Register
site /.*/
scrape "//a" do |a, env|
URI.join(env[:url], a[:href]).to_s
end
end
class Imgs < Faraday::Scraper::Register
site /.*/
scrape "//img" do |img, env|
URI.join(env[:url], img[:src]).to_s
end
end
end
connection = Faraday.new do |builder|
builder.use :scraper, Pages
builder.adapter :net_http
end
response = connection.get(...)
puts "links"
puts response.data["Links"] # => http://...
puts "images"
puts response.data["Imgs"] # => http://...
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request