Jsoup连接到“Javascript”链接

时间:2015-06-16 13:04:35

标签: java login jsoup

请考虑以下链接:

<a id="login" class="js-check" rel="nofollow" data-nop="" ref="javascript:void(0)">Login</a>

通过Jsoup,我可以按如下方式检索此元素:

Element bodyElement = doc.body();
Element A_Login = bodyElement.getElementById("login");

现在,我想跟Jsoup这个链接,我不知道我怎么能这样做?

FWIW,在浏览器中,单击此链接会生成注册/登录表单:

<form id="login_form" method="post" action="https://www.link.com/forum/login/">
  <table class="formTable">
    <tbody>
      <tr>
        <td><label class="required" for="login_login">Login</label></td>
        <td><input id="login_login" type="text" required="required" name="login[login]"> </td>
      </tr>

      <tr>
        <td><label class="required" for="login_password">Password</label></td>
        <td><input id="login_password" type="password" required="required" name="login[password]"></td>
      </tr>

      <tr>
        <td><button type="submit">Login</button></td>
     </tr>
  </tbody>
</table>
</form

当然,上述登录表单是异步加载的,不属于“基本”HTML内容..

如何在这种情况下使用Jsoup登录?

1 个答案:

答案 0 :(得分:0)

Jsoup不解释Javascript。因此,您需要自己分析脚本并创建简单的JSoup http客户端可以加载的相应URL,或者您可以使用完整的浏览器来获取链接。 Selenium http://www.seleniumhq.org/docs/03_webdriver.jsp与phantomjs http://phantomjs.org/结合使用是一个很好的解决方案。