如何使用Java和Eclipse在HTML网站上启动Jquery事件?

我正在尝试模拟学校门户网站登录页面上的按钮单击.但是,当我查看代码时,只看到名称和ID,然后看到“事件”按钮. “事件”按钮显示jquery文件重定向,该重定向用户重定向到特定链接.我附加了代码的某些部分.

如何在代码中启动该事件,以模拟按钮单击并自动重定向.

附言我会一直在检查答复,因此,如果没有足够的信息,请告诉我,这样我可以提出一个更好的问题.

[这是登录按钮代码图片

< input id =“ LoginButton” style =“ visibility:visible” type =“ button” value =“登录”>事件

我需要直接从我的应用程序中执行这些操作. (这位于index.PHP文件夹中

function gotologinreminder() {
    top.location = '/novi/StudentPortal/Home/LoginReminder';
};
$("#LoginButton").click(function () {
    $("#msgdisplay").hide();
    $("#imgwait").show();
    if ($("#Pin").val() == "" || $("#Password").val() == "") {
        $("#imgwait").hide();
        $("#msg1").show();
        return;
    };
    $("#loginform").submit();
});
$("#loginform").ajaxForm(function (retval) {
    if (retval.valid == "0") {
        $("#imgwait").hide();
        $("#msgmessage").html(retval.msg);
        $("#msgdisplay").show();
        $("#Pin").val("");
        $("#Password").val("");
        $("#Pin").focus();
    } else {
        $(window).off('resize.rightcolumn');
        top.location = '/novi/StudentPortal/Home/PortalMainPage';
    };
});
function clearmessages() {
    $("#msgdisplay").hide();
    $("#msg1").hide();
};

 

谢谢,

德米特里

最佳答案
如果我理解正确,则希望通过Java代码登录到网站,该网站具有用JavaScript编写的代码.在这种情况下,最好查看在Network tab in the developer console.中进行登录时发生的网络请求.特别是查看使用POST方法发出的那些请求,因为这意味着您的浏览器正在将信息发送到网站.我还建议使用Jsoup库,因为它可以简化此类请求.

编辑1:我做了album的屏幕截图,以帮助您理解.
最后一个图像是您将在java类中进行相同登录代码. (我模糊了一些信息,但您会明白的)

获取文档后,您还可以使用Jsoup here is the documentation刮取该网站.

注意:您显示的JS代码仅是验证和网站UI中的相应更改,例如,检查用户或密码是否为空,然后在网站上显示错误.实际的表单提交功能(retval)不在您显示代码中(至少据我所知).

要通过Jsoup传递登录cookie,您可以执行以下操作:

 Document profilePicDocument = Jsoup.connect(This is the new URL you want to access)
            .cookies(secondLoginPost.cookies()) //secondLoginPost is the last POST request
            .get();

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些