Java 使用selenium获取页面源代码,如何在没有firefox的服务器上使用我的代码?

Java 使用selenium获取页面源代码,如何在没有firefox的服务器上使用我的代码?,java,firefox,selenium,Java,Firefox,Selenium,当我使用selenium获取页面源代码时,它将通过系统Firefox使用selenium服务器。当服务器没有Firefox时,如何在服务器上加载代码 Web-driver driver = new Firefox-driver(); driver.navigate().to(url); String st = driver.getPageSource(); driver.close(); 您可以使用HtmlUnitDriver,而不是Firefo

当我使用selenium获取页面源代码时,它将通过系统Firefox使用selenium服务器。当服务器没有Firefox时,如何在服务器上加载代码

Web-driver driver = new Firefox-driver();
        driver.navigate().to(url);
        String st = driver.getPageSource();
        driver.close();

您可以使用HtmlUnitDriver,而不是FirefoxDriver

WebDriver driver = new HtmlUnitDriver();
driver.navigate().to(url);
String st = driver.getPageSource();
System.out.println(st);
driver.close();

我的问题得到了答案。。。 我们可以在服务器上安装firefox,并通过安装firefox为浏览器提供虚拟显示 X-Virtual帧缓冲区-无头Firefox 在Ubuntu中安装FirefoxHeadless,遵循以下命令 ppa:mozillateam/firefox稳定 更新源 sudoapt安装firefox 安装Xvfb–X虚拟帧缓冲区 sudoapt安装xvfb 下面的链接提供了详细信息

如果selenium仅用于抓取/爬行,则无头firefox是一个选项
点击链接

你打算做什么?看在上帝的份上,为什么要在服务器上执行selenium测试?您可以在您的计算机上本地运行测试,但使用生产(部署)url。我只想获取页面源代码。不做任何测试。不管您是只获取源代码还是运行测试。在部署服务器上运行selenium web驱动程序没有意义。也许您应该详细说明为什么需要页面的源代码-这是应用程序逻辑的一部分吗?是的,是我应用程序的一部分。由于无法使用httpclient和jsoup从页面源中获取特定数据,我使用的是selenium。使用HtmlUnit也无法获取我所需的数据。