liunx图形界面(ubuntu)下配置 selenium和chrome

cheome的下载地址(感谢网友整理归档,很方便)https://www.chromedownloads.net/chrome64linux-stable/

解压到ubuntu的桌面双击deb文件进行安装

然后下载对应版本driver

扔到/usr/selenium/路径中(先mkdir然后再cp过去)

 

 然后在java程序需要追加一些代码,判断系统类型,如果是linux的话,单独处理

  OSInfo.OSType ost = OSInfo.getOSType();

 

然后

if (ostypString.contains("LINUX")) {
            Map prefs = new HashMap();
            prefs.put("profile.default_content_settings.popups", 1); //设置为0禁止弹窗
            System.setProperty("webdriver.chrome.driver", "/usr/selenium/chromedriver");
            options.setExperimentalOption("prefs", prefs);
            options.addArguments("--headless");//无界面模式
        }

 启动程序,可以爬取了

 

posted @ 2020-12-10 10:58  不打鱼光晒网  阅读(305)  评论(0)    收藏  举报