I want to use selenium + phantomJs in my Spring boot project for scrapy. I can make it work in a normal java app like this :
System.setProperty("phantomjs.binary.path", path_to_phantomjs.exe);
PhantomJSDriver driver = new PhantomJSDriver();
driver.get(a_web_url);
WebElement e = driver.findElementByXPath("//button[@title='load-more']");
e.click();
JSWaiter.setDriver(driver);
JSWaiter.waitJsJQueryAngular();
String html = driver.getPageSource();
System.out.println(html);
driver.quit();
I set phantomJs in my spring boot project like this
main
|__java
|__resources
|__static
|__phantomJs
|__pahntomjs.exe
Whether I call :
public static void main(String[] args)
{
System.setProperty("phantomjs.binary.path", "static/phantomJs/phantomjs.exe");
SpringApplication.run(PricecompareApplication.class, args);
}
or :
@RequestMapping(value = {"/crawl"}, method = RequestMethod.POST)
public String crawlProduct(Model model, CrawlerOption crawlOption)
{
System.setProperty("phantomjs.binary.path", "static/phantomJs/phantomjs.exe");
PhantomJSDriver driver = new PhantomJSDriver(); // <-- always error at this
}
My program alway throw this error when i create a new PhantomJSDriver :
java.lang.IllegalAccessError: tried to access class org.openqa.selenium.os.ExecutableFinder from class org.openqa.selenium.phantomjs.PhantomJSDriverService
It seem like I set the wrong path or I can not access the resources, but when I use the path to phantomjs.exe in my console app (the first code block in my question), still the same error .
How can I config selenium + phantomjs in Spring boot?