[英]Jsoup javascript button clicking
How do I perform a click on a javascript button using Jsoup? 如何使用Jsoup执行单击javascript按钮?
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. 这是我用来设置网站中的用户名和密码字段的代码,但是当我抓取html时,它会给我输入页面填写的登录页面的html,而不是登录后的页面。 So that must mean that Jsoup simply filled the fields out, but didn't log me in. How would I go about doing that?
所以这必须意味着Jsoup只是填补了字段,但没有登录。我将如何去做? Also, the login button doesn't have an id element, nor does it have a name element.
此外,登录按钮没有id元素,也没有name元素。 It only has javascript.
它只有javascript。 Sorry if I'm not being clear, I'm new to this.
对不起,如果我不清楚,我是新手。 Here's the html code for the form:
这是表单的html代码:
<form name="form" id="form" method="POST" action="/portal/login?etarget=login_form" autocomplete="off">
This is the html code for the login button: 这是登录按钮的html代码:
<a href="javascript:document.form.event_override.value='login';document.form.submit();" class="btn_css">
How would I 'click' the login button using Jsoup? 如何使用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"
此外,我尝试使用.post()方法而不是.method(Method.POST),但是当我这样做时,我的程序没有工作,并给了我这条消息:“错误:400错误加载URL”
Also I do not own the website, and I'm using this in a native app that I'm building for Android. 此外,我不拥有该网站,我在我正在为Android构建的本机应用程序中使用它。
When passing a URL in connect method , instead of passing the Login Page URL , pass the link of home page. 在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();
Try this and you will get your result. 试试这个,你就会得到你的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.