Skip to content
Web crawler using resque
Pull request Compare This branch is 438 commits behind stewartmckee:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
README.textile
Rakefile
changelog.txt
cobweb.gemspec

README.textile

Cobweb v0.0.6

Intro

CobWeb has two functions. Firstly it is a http client that allows get and head requests returning a hash of data relating to the requested resource. The second main function is to utilize this combined with the power of Resque to cluster the crawls allowing you crawl quickly. When running on resque, passing in a Class and queue name it will enqueue all resources to this queue for processing, passing in the hash it has generated. You then implement the perform method to process the resource for your own application. The data available in the returned hash are:
  • :url – url of the resource requested
  • :status_code – status code of the resource requested
  • :mime_type – content type of the resource
  • :character_set – character set of content determined from content type
  • :length – length of the content returned
  • :body – content of the resource
  • :location – location header if returned
  • :redirect_through – if your following redirects, any redirects are stored here detailing where you were redirected through to get to the final location
  • :headers – hash or the headers returned
  • :links – hash or links on the page split in to types
    • :links – url’s from a tags within the resource
    • :images – url’s from img tags within the resource
    • :related – url’s from link tags
    • :scripts – url’s from script tags
    • :styles – url’s from within link tags with rel of stylesheet and from url() directives with stylesheets
The source for the links can be overridden, contact me for the syntax (don’t have time to put it into this documentation, will as soon as i have time!)

Installation

Install crawler as a gem

gem install cobweb

Usage

new(options)

Creates a new crawler object based on a base_url

  • options – Options are passed in as a hash,
  • :follow_redirects – transparently follows redirects and populates the :redirect_through key in the content hash (Default: true)
  • :redirect_limit – sets the limit to be used for concurrent redirects (Default: 10)
  • :processing_queue – specifies the processing queue for content to be sent to (Default: ContentProcessJob)
  • :debug – enables debug output (Default: false)
  • :quiet – hides default output (Default: false)
  • :cache – sets the ttl for caching pages, set to nil to disable caching (Default: 300)
  • :timeout – http timeout for requests (Default: 10)
  • :redis_options – hash containing the initialization options for redis (e.g. {:host => “redis.mydomain.com”}

crawler = CobWeb.new(:follow_redirects => false)

start(base_url)

Starts a crawl through resque. Requires the :processing_queue to be set to a valid class for the resque job to work with the data retrieved.

  • base_url – the url to start the crawl from

crawler.start(“http://www.google.com/”)

get(url)

Simple get that obey’s the options supplied in new.

  • url – url requested

crawler.get(“http://www.google.com/”)

head(url)

Simple get that obey’s the options supplied in new.

  • url – url requested

crawler.head(“http://www.google.com/”)

License

The MIT License

Copyright © 2010 6Central Limited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Something went wrong with that request. Please try again.