2012-07-26 1 views

Répondre

1

Tout ce que vous avez besoin est d'importer certaines classes de la bibliothèque:

import org.webharvest.definition.ScraperConfiguration; 
import org.webharvest.runtime.Scraper; 
import org.webharvest.runtime.variables.Variable; 

créer ScraperConfiguration objet avec votre fichier config.xml:

ScraperConfiguration config = null; 
    try { 
     config = new ScraperConfiguration("/path/to/config.xml"); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 

créer un objet grattoir avec chemin de travail dir:

Scraper scraper = new Scraper(config, "/tmp/"); 

et d'exécuter la configuration:

scraper.execute(); 

Vous pouvez également accéder à des variables après l'exécution de configuration:

String stringVar = 
     ((Variable)scraper.getContext().getVar("my_string_var")).toString(); 
    List<Variable> listVar = 
     ((Variable) scraper.getContext().getVar("my_list_var")).toList(); 

You can see example here

And also API here