新增PhantomJSDownloader构造函数,支持crawl.js路径自定义,因为当其他项目依赖此jar包时,runtime.exec()执行phantomjs命令时无使用法jar包中的crawl.js
parent
f8a2328ead
commit
d1f2e65e5d
|
@ -44,6 +44,11 @@ public class PhantomJSDownloader extends AbstractDownloader {
|
||||||
PhantomJSDownloader.phantomJsCommand = phantomJsCommand;
|
PhantomJSDownloader.phantomJsCommand = phantomJsCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PhantomJSDownloader(String phantomJsCommand, String crawlJsPath) {
|
||||||
|
PhantomJSDownloader.phantomJsCommand = phantomJsCommand;
|
||||||
|
PhantomJSDownloader.crawlJsPath = crawlJsPath;
|
||||||
|
}
|
||||||
|
|
||||||
private void initPhantomjsCrawlPath() {
|
private void initPhantomjsCrawlPath() {
|
||||||
PhantomJSDownloader.crawlJsPath = new File(this.getClass().getResource("/").getPath()).getPath() + System.getProperty("file.separator") + "crawl.js ";
|
PhantomJSDownloader.crawlJsPath = new File(this.getClass().getResource("/").getPath()).getPath() + System.getProperty("file.separator") + "crawl.js ";
|
||||||
}
|
}
|
||||||
|
@ -86,7 +91,7 @@ public class PhantomJSDownloader extends AbstractDownloader {
|
||||||
try {
|
try {
|
||||||
String url = request.getUrl();
|
String url = request.getUrl();
|
||||||
Runtime runtime = Runtime.getRuntime();
|
Runtime runtime = Runtime.getRuntime();
|
||||||
Process process = runtime.exec(phantomJsCommand + " " + crawlJsPath + url);
|
Process process = runtime.exec(phantomJsCommand + " " + crawlJsPath + " " + url);
|
||||||
InputStream is = process.getInputStream();
|
InputStream is = process.getInputStream();
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
|
Loading…
Reference in New Issue