【发布时间】:2018-10-27 18:01:08
【问题描述】:
我想创建一个简单的 python 脚本,它将登录到我的路由器网站,关闭 wifi 然后应用更改并执行相反的操作(打开 wifi 并应用更改),不幸的是我对 html 标记的了解而且python还不够好,所以请帮助我:)
这是我目前创建的:
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
import requests
my_url = 'http://router/WLG_adv.htm'
response = requests.get(my_url, auth=requests.auth.HTTPBasicAuth('My_username', 'My_password'))
c = response.content
uClient = uReq(my_url)
soup = BeautifulSoup(c)
rows = soup.findAll('tr')[4::5]
soup.find("button", "button-apply")
...感谢我能够使用凭据登录到正确的页面并获得正确的代码来操作:
这是“wifi 启用复选框部分”(我相信它是 check_wifi_sche())
[<tr>
<td colspan="2">
<input checked="" name="enable_ap" onclick="check_wifi_sche()" type="checkbox" value="enable_ap"/> Enable Wireless Router Radio </td></tr>, <tr>
<td colspan="2">
<div id="wifi_sche_div1">
<input name="wifi_onoff" type="checkbox" value="wifi_onoff"/> Turn off wireless signal by schedule
</div>
</td>
</tr>, <tr><td colspan="2" height="12"><div style="background-image:url('liteblue.gif');width:100%"> </div></td></tr>, <tr>
<td colspan="2">
<input checked="" name="wsc_config" type="checkbox"/>
<font> Keep Existing Wireless Settings </font>
</td>
</tr>]
这里是“应用按钮部分”:
>>> soup.find("button", "button-apply")
<button class="button-apply" name="Apply" onclick="buttonClick(this,'Apply');return checkData();" type="submit" value="Apply"> <span class="roundleft_apply">Apply <span class="apply-icon"> </span></span><span class="roundright_apply"> </span></button>
提前致谢。
【问题讨论】:
-
使用 selenium,它是你想要做的事情的合适工具
标签: python html beautifulsoup python-requests urllib