我目前正在研究一個python腳本,它需要我在本地路由器的DHCP服務器上獲取當前客戶端的列表。我首先想到的是如何使用requests來獲取包含列表(http://192.168.2.1/lan_dhcp.stm
)的網頁,然後解析數據並使用它。使用Python獲取DHCP客戶端列表
問題是,有時,路由器的Web界面會要求我登錄,即使沒有設置密碼,您只需點擊提交。我如何通過Python發送請求登錄(http://192.168.2.1/login.htm
)以保證我能夠訪問客戶端列表?有沒有更好的方法來做到這一點? login.cgi
:網頁
<form action="login.cgi" method="post" name="tF" onsubmit="checkfwVersion()">
<input type="hidden" name="totalMSec" value="">
<input type="hidden" name="pws" value="">
<input type="hidden" name="arc_action" value="login">
<table border="0" cellspacing="0" cellpadding="0" align="left" width="100%" height="100%">
<tbody>
<tr>
<td valign="top" width="99%" height="100%" class="head_bold">
<br>
<font color="#0000ff"> Login</font>
<br>
<!--This is Login.stm-->
<table border="0" class="copy_1">
<tbody>
<tr>
<td width="5" colspan="2"> </td>
</tr>
<tr>
<td width="5"> </td>
<td>
<table width="480" border="0" cellspacing="5" cellpadding="0" align="left" class="copy_1">
<tbody>
<tr>
<td width="69" height="41"> </td>
<td height="41" class="body" colspan="2">
Before you can change any settings, you need to login with a password. If you have
not yet set a custom password,
then leave this field blank and
click "Submit."
</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="69"> </td>
<td width="146" class="body"><b>Password</b>
</td>
<td width="250">
<input type="password" maxlength="12" size="16" name="pws_temp">
</td>
</tr>
<tr>
<td width="69" class="body"> </td>
<td colspan="2">
<font color="#6F4AFD"><b>Default = leave blank</b></font>
</td>
</tr>
<tr>
<td width="69" colspan="3"> </td>
</tr>
<tr>
<td width="69"> </td>
<td colspan="2" align="center">
<nobr>
<input type="button" onclick="javascript:document.tF.reset();" value="Clear" style="{width=120px;height=22px;}"
class="submitBtn" onmouseover="window.status='Clear'; return true;"
onmouseout="window.status=''; return true;">
<input type="submit" name="action" value="Submit" style="{width=120px;height=22px;}"
class="submitBtn">
</nobr>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
嘿@alecxe,遺憾的遲到的答案。我試着用[** this **](https://gist.github.com/Arengorn/98a540fa8081d7453677)這樣的方法,但是我得到了下面的[**錯誤**](https:// gist。 github.com/Arengorn/f0a571356d0610f80b7e)。我究竟做錯了什麼? –
[** ghostdriver.log **](https://gist.github.com/Arengorn/c70b265b81d33110386d) –
@BernardMeurer可能是多種原因。您能否使用登錄表單完成頁面的完整HTML?謝謝! – alecxe