phantomjs.exe下载

1努力加油1 2019-03-05 06:58:02
phantomjs highcarts export 用到
相关下载链接://download.csdn.net/download/yexiufei123/8876537?utm_source=bbsseo
...全文
61 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
需要的添加的jar包及工具:我这里使用maven来构建项目,添加依赖如下:   org.seleniumhq.selenium   selenium-java   3.2.0    PhantomJs工具到官网去下载:http://phantomjs.org/download.html 尽量都使用最新版本,不然会出现版本兼容的情况。 这里有一个已经写好的获取PhantomJSDriver的工具类 public static WebDriver getPhantomJs() {   String osname = System.getProperties().getProperty("os.name");   if (osname.equals("Linux")) {//判断系统的环境win or Linux     System.setProperty("phantomjs.binary.path", "/usr/bin/phantomjs");   } else {     System.setProperty("phantomjs.binary.path", "./phantomjs/win/phantomjs.exe");//设置PhantomJs访问路径   }   DesiredCapabilities desiredCapabilities = DesiredCapabilities.phantomjs();   //设置参数   desiredCapabilities.setCapability("phantomjs.page.settings.userAgent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");   desiredCapabilities.setCapability("phantomjs.page.customHeaders.User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:50.0) Gecko/20100101   Firefox/50.0");   if (Constant.isProxy) {//是否使用代理     org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();     proxy.setProxyType(org.openqa.selenium.Proxy.ProxyType.MANUAL);     proxy.setAutodetect(false);     String proxyStr = "";     do {       proxyStr = ProxyUtil.getProxy();//自定义函数,返回代理ip及端口     } while (proxyStr.length() == 0);     proxy.setHttpProxy(proxyStr);     desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);   }   return new PhantomJSDriver(desiredCapabilities); } 获取方式     try{     WebDriver webDriver = PhantomJsUtil.getPhantomJs();     webDriver.get(url);     SleepUtil.sleep(Constant.SEC_5);     PhantomJsUtil.screenshot(webDriver);     WebDriverWait wait = new WebDriverWait(webDriver, 10);     wait.until(ExpectedConditions.presenceOfElementLocated(By.id(inputId)));//开始打开网页,等待输入元素出现     Document document = Jsoup.parse(webDriver.getPageSource());     //TODO  剩下页面的获取就按照Jsoup获取方式来做   }finally{     if (webDriver != null) {       webDriver.quit();     }   } python版使用webdriver+PhantomJs爬虫使用,参考http://www.cnblogs.com/kuqs/p/6395284.html

12,793

社区成员

发帖
与我相关
我的任务
社区描述
CSDN 下载资源悬赏专区
其他 技术论坛(原bbs)
社区管理员
  • 下载资源悬赏专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧