gpt4 book ai didi

java - 在 htmlunit 中读取网页的移动版本

转载 作者:太空宇宙 更新时间:2023-11-04 11:01:37 25 4
gpt4 key购买 nike

我正在尝试使用htmlunit库访问java中的网页。我可以成功阅读常规桌面浏览器的页面,但现在我想阅读相同网页的移动版本,基本上是手机浏览器中出现的原始 HTML,但我不能。

我尝试使用手机规范定义一个新的 BrowserVersion 类,如下所示。但是当我读取网页时,读取的值不是移动版网页(与桌面版网页相同)。

    String applicationName = "Chrome";
String applicationVersion = "5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19";
String userAgent = "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19";
int browserVersionNumeric = 51;
BrowserVersion browser = new BrowserVersion(applicationName, applicationVersion, userAgent, browserVersionNumeric);
WebClient webClient = new WebClient(browser);

任何人都可以帮助我阅读网页的移动版本。

最佳答案

一些提示:

  • 使用 HtmlUnit 的最新快照始终是一个好主意。对于您的情况,您将面临重大的界面更改,因为创建新浏览器版本的方式已更改。
  • 我猜您的网页可能会考虑屏幕尺寸
  • 也许页面是相同的,只是 css 负责屏幕尺寸,您只会得到不同的视觉结果

关于java - 在 htmlunit 中读取网页的移动版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46839065/

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