【发布时间】:2017-01-23 01:28:43
【问题描述】:
我正在尝试编写一个自动更新页面内容的应用程序(在我的帐户中)。我使用了 HTMLUnit,因为它支持 javascript。 但是我遇到了“您的浏览器太旧”的问题。
我的代码:
public static void main(String[] args) {
Locale.setDefault(Locale.ENGLISH);
try (final WebClient client = new WebClient(BrowserVersion.FIREFOX_45)) {
client.getOptions().setUseInsecureSSL(true);
client.setAjaxController(new NicelyResynchronizingAjaxController());
client.getOptions().setThrowExceptionOnFailingStatusCode(false);
client.getOptions().setThrowExceptionOnScriptError(false);
client.waitForBackgroundJavaScript(30000);
client.waitForBackgroundJavaScriptStartingBefore(30000);
client.getOptions().setCssEnabled(false);
client.getOptions().setJavaScriptEnabled(true);
client.getOptions().setRedirectEnabled(true);
HtmlPage page = client.getPage("https://passport.yandex.ru/passport?mode=auth&retpath=https://toloka.yandex.ru/?ncrnd=5645");
HtmlForm form = page.getForms().get(0);
HtmlInput inputLogin = form.getInputByName("login");
inputLogin.setValueAttribute(userName);
HtmlInput inputPassw = form.getInputByName("passwd");
inputPassw.setValueAttribute(password);
DomElement button = page.getElementsByTagName("button").get(0);
HtmlPage page2 = button.click();
System.out.println(page2.asXml());
}
catch (IOException e) {
}
}
登录成功,但我无法加载第二页。 (它应该重定向到内容页面)
答案:
<h1 style="padding-top: 20px;">Browser is too old</h1>
<p>
Unfortunately you are using an old browser.
Please, upgrade to at least IE10 or use one of the modern browsers, e.g.
<a href="http://browser.yandex.net/">Yandex.Browser</a>,
<a href="https://www.google.com/chrome/browser/">Google Chrome</a> or
<a href="https://www.mozilla.org/firefox/new/">Mozilla Firefox</a>
</p>
我该如何解决?谢谢。
【问题讨论】: