【问题标题】:Jsoup javascript button clickingJsoup javascript按钮点击
【发布时间】:2012-01-04 02:32:28
【问题描述】:

如何使用 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 构建的本机应用程序中使用它。

【问题讨论】:

  • 你有没有收到过这方面的回复?

标签: javascript android html forms jsoup


【解决方案1】:

在 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();  

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

【讨论】:

  • 主页上没有“login_name”和“password”元素。我试过了,但 .post() 方法再次给了我“错误:400 错误加载 URL”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
  • 1970-01-01
相关资源
最近更新 更多