Android to execute web js
Android to execute web js
我正在编写一个可以自动登录网站的应用程序。有一个Javascript函数提交表单。我通过在Google Chrome控制台输入它来测试它,并且它工作了。有人能告诉我如何在Java中做到这一点吗?请帮助我。下面是表单HTML代码:
<form target="_blank" method="POST" id="login_form2" action="https://webcat.hkpl.gov.hk/auth/login?wicket:interface=:0:loginPanel:loginForm::IFormSubmitListener::&theme=WEB&locale=zh_TW">
<h4 class="orange">我的帳戶</h4>
<label style="display:none" for="acc-box2">號碼</label>
<input title="號碼" data-hint="號碼" class="text-field" name="username" type="password" style="display: none;" id="acc-box2">
<input title="號碼" value="號碼" type="text" class="text-field" style="width: 150px; margin-bottom: 5px; display: block;">
<label class="orange show_pass" for="show-check2"><input title="顯示" id="show-check2" type="checkbox" name="c2">顯示</label>
<label style="display:none" for="pass-box2">網上密碼</label>
<input value="004484284548649879936:lcyfpggwj-i" name="cx" type="hidden">
<input value="UTF-8" name="ie" type="hidden">
<input style="display: none;" class="text-field" name="password" type="password" id="pass-box2">
<input style="width:150px;margin-bottom:5px;" class="text-field" type="text" value="網上密碼" title="網上密碼">
<input type="submit" title="提交" style="display:none;">
<div style="clear:both;"></div>
<a onclick="$('#login_form2').submit()" class="ac_login_btn" href="javascript:void(0)">
<img height="32" width="94" title="登入" alt="登入" src="/common/tc/images/main_login_btn.png">
</a>
<div style=" vertical-align: top; line-height: 1; font-size: small; padding-left: 100px; color: #c63006; ">請緊記在關閉瀏覽器視窗前,先要登出你的帳戶。</div>
</form>
提交函数是$('#login_form2').submit()
在java中你可以试试这个,如果你想从应用程序登录到网站
public static void loginToSite(HttpClient client, String username, String password){
List<NameValuePair> attributes = new ArrayList<NameValuePair>();
attributes .add(new BasicNameValuePair("email", username));
attributes .add(new BasicNameValuePair("pword", password));
attributes .add(new BasicNameValuePair("action", "modifyPALS"));
attributes .add(new BasicNameValuePair("Submit", "Login"));
HttpPost httpPost = new HttpPost();
try{
httpPost .setURI(new URI("https://webcat.hkpl.gov.hk/auth/login"));
httpPost .setEntity(new UrlEncodedFormEntity(attributes ));
client.execute(httpPost );
AppStatus s = getSiteConnectionStatus(client, site);
}
catch (URISyntaxException e){
e.printStackTrace();
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
但我不确定这是不是你想要的
如果你想把整个项目转换成java,你必须自己做。你不应该指望任何人为你做这件事。
我可以提个建议,这样你就不用把所有东西都转换成java了。你可以使用Webview并在那个Webview中加载html文件。在这种情况下,您不必在java中重写表单。
相关文章:
- 托管时,angular.js web应用程序中未显示内容
- 在JS web应用程序中,如何确保具有访问令牌的恶意用户无法刷新它
- 节点.js Web 服务器中的结束后写入错误
- 节点.js Web 服务器不会重新加载
- 如何从节点.js Web 服务器连接到数据库服务器
- 将 Outlook 与 JS Web 应用程序集成
- 构建一个角度合理的 JS Web 项目
- Node.js Web 服务是什么样的
- 如何在我的节点中包含另一个参数.js Web 服务
- 使用Backbone.js在待办事项中对数据集合进行分页.js Web应用程序
- Node JS web服务器中的函数管道
- 如何在JS web worker中循环查询worker的可用性而不阻塞
- 从客户端向Node.js Web服务器发送JSON
- Node.js Web服务器;显示pgp-asc文件的内容,而不是提示下载
- js web工作程序内存泄漏
- 我应该如何编写一个同时包含服务器端和客户端代码的node.js web应用程序
- JS/web调试器跟踪HTTP请求的来源
- 如何在angular js web应用中使用ckeditor
- 如何通过angular js将数组插入到node js web服务中
- Three.js Web Worker兼容吗?importScripts("three.js")给出