我有一个XML配置(ScreenScraper),它可以在WebHarvest的可执行版本中正确地执行我想要的操作。我对如何通过Java执行它感到困惑。
发布于 2012-08-01 07:02:32
你需要做的就是从库中导入一些类:
import org.webharvest.definition.ScraperConfiguration;
import org.webharvest.runtime.Scraper;
import org.webharvest.runtime.variables.Variable;使用config.xml文件创建object ScraperConfiguration:
ScraperConfiguration config = null;
try {
config = new ScraperConfiguration("/path/to/config.xml");
} catch (FileNotFoundException e) {
e.printStackTrace();
}使用指向工作目录的路径创建对象搜索器:
Scraper scraper = new Scraper(config, "/tmp/");并执行配置:
scraper.execute();您也可以在配置执行后访问变量:
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
https://stackoverflow.com/questions/11677881
复制相似问题