0

WebHarvest の実行可能バージョンで必要なことを正しく実行する XML 構成 (ScreenScraper) があります。Javaを介して実行する方法について混乱しています。

4

1 に答える 1

1

必要なのは、ライブラリからいくつかのクラスをインポートすることだけです。

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

config.xmlファイルを使用してオブジェクトScraperConfigurationを作成します。

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

作業ディレクトリへのパスを持つオブジェクトScraperを作成します。

    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();

ここで例を見ることができます

また、ここのAPI

于 2012-07-31T23:02:31.683 に答える