Jsoup javascript 按钮点击

发布于 2024-12-23 21:34:17 字数 937 浏览 3 评论 0原文

如何使用 Jsoup 单击 javascript 按钮?

 String html = Jsoup.connect(url)
                .followRedirects(true)
                .data("login_name", username)
                .data("password", userpassword)
                .method(Method.POST).get().html();

这是我用来在网站中设置用户名和密码字段的代码,但是当我抓取 html 时,它为我提供了填写了页面字段的登录页面的 html,而不是登录后的页面。所以这肯定意味着 Jsoup 只是填写了字段,但没有让我登录。我该怎么做呢?此外,登录按钮没有 id 元素,也没有 name 元素。它只有 JavaScript。抱歉,如果我不清楚,我是新手。这是表单的 html 代码:

 <form name="form" id="form" method="POST" action="/portal/login?etarget=login_form" autocomplete="off"> 

这是登录按钮的 html 代码:

<a href="javascript:document.form.event_override.value='login';document.form.submit();" class="btn_css">    

如何使用 Jsoup“单击”登录按钮?另外,我尝试使用 .post() 方法而不是 .method(Method.POST),但是当我这样做时,我的程序不起作用,并给了我这条消息:“错误:400 错误加载 URL”

另外我不拥有该网站,我在为 Android 构建的本机应用程序中使用该网站。

How do I perform a click on a javascript button using Jsoup?

 String html = Jsoup.connect(url)
                .followRedirects(true)
                .data("login_name", username)
                .data("password", userpassword)
                .method(Method.POST).get().html();

This is the code I used to set the username and password fields in a website, however when I grab the html, it gives me the html of the login page with the page's fields filled out, rather than the page after login. So that must mean that Jsoup simply filled the fields out, but didn't log me in. How would I go about doing that? Also, the login button doesn't have an id element, nor does it have a name element. It only has javascript. Sorry if I'm not being clear, I'm new to this. Here's the html code for the form:

 <form name="form" id="form" method="POST" action="/portal/login?etarget=login_form" autocomplete="off"> 

This is the html code for the login button:

<a href="javascript:document.form.event_override.value='login';document.form.submit();" class="btn_css">    

How would I 'click' the login button using Jsoup? Also, I tried using the .post() method instead of .method(Method.POST), however when I did that, my program didn't work, and gave me this message: "Error: 400 error loading URL"

Also I do not own the website, and I'm using this in a native app that I'm building for Android.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾其所爱 2024-12-30 21:34:17

在 connect 方法中传递 URL 时,不要传递登录页面 URL,而是传递主页的链接。

Document doc = Jsoup.connect("http://www.website.com/home.php")
  .data("email", "myemailid")
  .data("pass", "mypassword")
  // and other fields which are being passed in post request.
  .userAgent("Mozilla")
  .post();  

试试这个,你就会得到结果。

When passing a URL in connect method , instead of passing the Login Page URL , pass the link of home page.

Document doc = Jsoup.connect("http://www.website.com/home.php")
  .data("email", "myemailid")
  .data("pass", "mypassword")
  // and other fields which are being passed in post request.
  .userAgent("Mozilla")
  .post();  

Try this and you will get your result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文