0
我正在嘗試編寫自動更新頁面內容(在我的帳戶內)的應用程序。我使用HTMLUnit是因爲它支持javascript。 但我面臨「你的瀏覽器太舊」的問題。HTMLUnit Java太舊的瀏覽器
我的代碼:
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>
我怎樣才能解決呢?謝謝。
謝謝,但它沒有幫助。 2017年1月22日下午8:57:38 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl通知 警告:遇到過時的內容類型:'application/x-javascript'。 (我不知道這是什麼意思,因爲我根本不知道JS) – Limmy
那麼,在java中沒有任何方式來做這個應用程序? 「 – Limmy
」謝謝,但它沒有幫助「 - 什麼沒有幫助?關於日誌輸出:這是一個警告,這個可以忽略。如果你想自動化一個網頁,你需要一個關於網頁基礎的良好知識,比如Http,Html和Javascript。 – RBRi