scrappy¶ ↑
DESCRIPTION:¶ ↑
Scrappy is a tool that allows extracting information from web pages and producing RDF data. It uses the scraping ontology to define the mappings between HTML contents and RDF data.
An example of mapping is shown next, which allows extracting all titles from www.elmundo.es:
dc: http://purl.org/dc/elements/1.1/ rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns# sioc: http://rdfs.org/sioc/ns# sc: http://lab.gsi.dit.upm.es/scraping.rdf# *: rdf:type: sc:Fragment sc:selector: *: rdf:type: sc:UriSelector rdf:value: "http://www.elmundo.es/" sc:identifier: *: rdf:type: sc:BaseUriSelector sc:subfragment: *: sc:type: sioc:Post sc:selector: *: rdf:type: sc:CssSelector rdf:value: ".noticia h2, .noticia h3, .noticia h4" sc:identifier: *: rdf:type: sc:CssSelector rdf:value: "a" sc:attribute: "href" sc:subfragment: *: sc:type: rdf:Literal sc:relation: dc:title sc:selector: *: rdf:type: sc:CssSelector rdf:value: "a"
(The above code is serialized using YARF format, supported by LightRDF gem, as well as RDFXML, JSON, NTriples formats, which can also be used to define the mappings).
SYNOPSIS:¶ ↑
A knowledge base of mappings can be defined by storing RDF files inside ~/.scrappy/extractors folder. Then, the command-line tool can be used to get RDF data from web sites. You can get help on this tool by typing:
$ scrappy --help
Scrappy offers many different interfaces to get RDF data from a web page:
-
Command-line interface:
$ scrappy -g example.com
-
Web Admin interface:
$ scrappy -a Launching Scrappy Web Admin (browse http://localhost:3434)... == Sinatra/1.1.3 has taken the stage on 3434 for production with backup from Thin
Then point your browser to localhost:3434 for additional directions.
-
Web Service interface:
$ scrappy -s Launching Scrappy Web Server... == Sinatra/1.1.3 has taken the stage on 3434 for production with backup from Thin
Then use the service in the same way as the Web Admin but for read-only operations.
-
Ruby interface:
You can use Scrappy in a Ruby program by requiring the gem:
require 'rubygems' require 'scrappy' # Parse a knowledge base kb = RDF::Parser.parse :yarf, open("https://github.com/josei/scrappy/raw/master/kb/elmundo.yarf").read # Set kb as default knowledge base Scrappy::Agent::Options.kb = kb # Create an agent agent = Scrappy::Agent.new # Get RDF output output = agent.request :method=>:get, :uri=>'http://www.elmundo.es' # Output all titles from the web page titles = output.find([], Node('dc:title'), nil) titles.each { |title| puts title }
-
RDF repository:
Sesame functionality has been included in Scrappy. You can configure the repository options by editing the file config.yml placed the folder .scrappy, in your home dir. An example of this file can be found at the end of this README.
You can get the data for a certain period of time, by using the time (-t, –time) option:
$ scrappy -g example.org -t 3
This would get all the data stored in Sesame for example.org in the last 3 minutes.
-
Sample config.yml
# This is a sample configuration file, with the options to communicate with Sesame using Scrappy repository: # The host were Sesame is. Do not add the trailing '/' host: http://localhost # The port for the connection port: 8080 # The time to consider the data in the repository valid, in minutes time: 15 # The name of the repository repository: memory # The format to communicate with the repository format: ntriples # You can use any of the following formats: # rdfxml, ntriples, turtle, n3, trix, trig
INSTALL:¶ ↑
Install it as any other gem:
$ gem install scrappy
The gem also requires raptor library (in Debian systems: sudo aptitude install raptor-utils), which is used for outputting different RDF serialization formats.
PNG output of RDF graphs requires Graphviz (in Debian systems: sudo aptitude install graphviz).
In order to use Sesame, you will need to install it. Further instructions can be found in the openRDF website, more precisely, in www.openrdf.org/doc/sesame2/users/ch06.html .
CONTRIBUTORS:¶ ↑
-
José Ignacio Fernández
-
Alberto Mardomingo
-
Jacobo Blasco
LICENSE:¶ ↑
(The MIT License)
Copyright © 2010 José Ignacio Fernández (joseignacio.fernandez <at> gmail.com)
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.