gpt4 book ai didi

java - 模拟打开网页 - Java

转载 作者:行者123 更新时间:2023-11-27 23:40:31 25 4
gpt4 key购买 nike

我想在 java 中模拟打开网页,我知道我可以这样做以在我的计算机上的浏览器中实际打开该页面,

String htmlFilePath = "path/to/html/file.html"; // path to your new file
File htmlFile = new File(htmlFilePath);

// open the default web browser for the HTML page
Desktop.getDesktop().browse(htmlFile.toURI());

// if a web browser is the default HTML handler, this might work too
Desktop.getDesktop().open(htmlFile);

但是有没有办法模拟它,所以我实际上并没有看到它在我的电脑上打开,但它仍然像有人打开网页一样评估。

或者,如果这不可能,那么在我的计算机上物理打开它然后获得回调以便我知道页面何时加载的最简单方法是什么?

谢谢

最佳答案

有几种方法可以模拟 HTTP 客户端(例如网络浏览器):

  1. Jersey ( java )- https://jersey.java.net/documentation/latest/client.html
  2. Apache HTTPClient (Java) - https://hc.apache.org/
  3. JMeter (Java) - 使用 JMeter 记录 HTTP 请求并将其重播为测试 - https://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf
  4. Selenium(浏览器插件)- http://www.seleniumhq.org/
  5. CURL(命令行工具)- http://curl.haxx.se/

我建议您使用 Jersey。它是专门为 REST 设计的工具。因此它甚至可能有助于服务器端开发。

我知道您特别要求 Java 解决方案,但最后两个选项非常受欢迎。

关于java - 模拟打开网页 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31925835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com