问题:
PhantomJS java hello
解决:
- 下载 phantomjs
- 创建maven 项目添加依赖
|
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories> <dependency> <groupId>com.github.detro</groupId> <artifactId>phantomjsdriver</artifactId> <version>2.0.0</version> </dependency> |
- 代码
|
DesiredCapabilities c = DesiredCapabilities.phantomjs(); c.setCapability("phantomjs.binary.path", "E:\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe"); PhantomJSDriver driver = new PhantomJSDriver(c); driver.get("http://www.baidu.com"); //WebElement body = (new WebDriverWait(driver, 10)) //.until(ExpectedConditions.presenceOfElementLocated(By.tagName("body"))); //final String title = driver.getTitle(); //System.out.println("title " + title); System.out.println(""+driver.getPageSource()); driver.quit(); |
参考:
http://phantomjs.org/
https://github.com/detro/ghostdriver