首页 » Web前端 » phpselenium教程pdf技巧_5LINUX HTML 转 PDFselenium

phpselenium教程pdf技巧_5LINUX HTML 转 PDFselenium

访客 2024-10-24 0

扫一扫用手机浏览

文章目录 [+]

这种分离是故意识地努力让浏览器供应商为其浏览器的实现卖力的一部分。
Selenium 在可能的情形下利用这些第三方驱动程序, 但是在这些驱动程序不存在的情形下,它也供应了由项目自己掩护的驱动程序。

Selenium 框架通过一个面向用户的界面将所有这些部分连接在一起, 该界面许可透明地利用不同的浏览器后端, 从而实现跨浏览器和跨平台自动化。

phpselenium教程pdf技巧_5LINUX HTML 转 PDFselenium

selenium 驱动

# selenium 驱动https://selenium-python.readthedocs.io/installation.html#drivershttps://selenium-python.readthedocs.io/api.htmlselenium-java紧张依赖

<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.16.1</version> </dependency>测试代码

// 获取 java 版本 String version = System.getProperty("java.specification.version"); // 获取系统类型 String platform = System.getProperty("os.name", ""); platform = platform.toLowerCase().contains("window") ? "win" : "linux"; // 当出路序目录 String current = System.getProperty("user.dir"); System.out.println("current:" + current); // firefox 运行参数配置 FirefoxOptions options = new FirefoxOptions(); // 无头模式 options.addArguments("--headless"); // 最大化 options.addArguments("--start-maximized"); FirefoxDriver browser = new FirefoxDriver(options); Path url = Paths.get(current, "..", "index.html"); System.out.println("url:" + url.toString()); // NOTE 要利用 file 协议 browser.get(String.format("file://%s", url.toString())); // 打印设置 PrintOptions print = new PrintOptions(); Pdf pdf = browser.print(print); // pdf base64 内容 String content = pdf.getContent(); // 解码内容 Base64.Decoder decoder = Base64.getDecoder(); byte[] buffer = decoder.decode(content); try { // 将 byte 写入文件 Path file = Paths.get(String.format("java%s_%s.pdf", version, platform)); Files.write(file, buffer); } catch (IOException e) { throw new RuntimeException(e); } finally { browser.quit(); }效果预览

selenium/java11_linux.pdf · yjihrp/linux-html2pdf-demo - Gitee.com

phpselenium教程pdf技巧_5LINUX HTML 转 PDFselenium
(图片来自网络侵删)

selenium/java11_win.pdf · yjihrp/linux-html2pdf-demo - Gitee.com

测试结果

测试结果

下一篇 6-LINUX HTML 转 PDF-selenium-python

标签:

相关文章

天刀自由摄像代码探索虚拟世界的无限可能

虚拟现实技术逐渐走进我们的生活。天刀自由摄像代码作为一款虚拟现实游戏《天涯明月刀》的辅助工具,为玩家们带来了全新的游戏体验。本文将...

Web前端 2025-02-18 阅读0 评论0

国君转债申购代码投资机遇与风险防范

可转债作为一种兼具债券和股票特性的金融工具,越来越受到投资者的关注。近期,国君转债申购代码的公布,再次引发了市场的热烈讨论。本文将...

Web前端 2025-02-18 阅读0 评论0

旺旺群社交新宠,如何成为年轻人的聚集地

社交平台层出不穷,而在这其中,旺旺群以其独特的魅力和功能,迅速成为年轻人的聚集地。本文将从旺旺群的发展历程、特点、优势等方面进行探...

Web前端 2025-02-18 阅读0 评论0