[英]Jsoup to connect to a “Javascript” link
考慮以下鏈接:
<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登錄?
Jsoup不解釋Javascript。 因此,您要么需要自己分析腳本並創建簡單的JSoup http客戶端可以加載的適當的URL,要么就可以使用完整的瀏覽器來獲取鏈接。 Selenium http://www.seleniumhq.org/docs/03_webdriver.jsp與phantomjs http://phantomjs.org/結合是一個很好的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.