A loose framework for crawling and scraping web sites.
A loose framework for crawling and scraping web sites.
Spidey provides a bare-bones framework for crawling and scraping web sites. Its goal is to keep boilerplate scraping logic out of your code.
This example spider crawls an eBay page, follows links to category pages, continues to auction detail pages, and finally records a few scraped item details as a result.
class EbayPetSuppliesSpider [{category: "Aquarium & Fish", title: "5 Gal. Fish Tank"...Implement a spider class extending Spidey::AbstractSpider for each target site. The class can declare starting URLs by calling handle at the class level. Spidey invokes each of the methods specified in those calls, passing in the resulting page (a Mechanize Page object) and, optionally, some scraped data. The methods can do whatever processing of the page is necessary, calling handle with additional URLs to crawl and/or record with scraped results.
By default, the lists of URLs being crawled, results scraped, and errors encountered are stored as simple arrays in the spider (i.e., in memory):
spider.urls # => ["http://www.ebay.com", "http://www.ebay.com/...", ...]
spider.results # => [{auction_title: "...", sale_price: "..."}, ...]
spider.errors # => [{url: "...", handler: :process_home, error: FooException}, ...]Add the spidey-mongo gem and include Spidey::Strategies::Mongo in your spider to instead use MongoDB to persist these data. See the docs for more information. Or, you can implement your own strategy by overriding the appropriate methods from AbstractSpider.
You may set Spidey.logger to a logger of your choosing. When used in a Rails environment, the logger defaults to the Rails logger. Otherwise, it's directed to STDOUT.
Spidey is very much a work in progress. See CONTRIBUTING for details.
Copyright (c) 2012-2015 Joey Aghion, Artsy Inc. See LICENSE.txt for further details.
No open issues yet, or sync has not completed.