Jsoup javascript 按钮点击
如何使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 connect 方法中传递 URL 时,不要传递登录页面 URL,而是传递主页的链接。
试试这个,你就会得到结果。
When passing a URL in connect method , instead of passing the Login Page URL , pass the link of home page.
Try this and you will get your result.