Python脚本,单击启用/禁用WiFi



我想创建一个简单的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>

提前谢谢。

我终于解决了这个问题。谢谢你的提示,德夫,这真的很有帮助。因此,我的任务是编写一个简单的脚本来启用/禁用Wifi,并单击NETGEAR WNR3500Lv2路由器的应用按钮。

如果有人需要,我会发布如何操作的信息:((注意,在路由器地址行中(你必须把你的路由器凭据放在我放X和Y的地方。

# -*- coding: latin-1 -*-                   
# Ranorex selocity do chrome'a               <<< Very helpful tool for chrome to extract paths from websites.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()   # Remember to have your chrome driver in $PATH (download driver from google)
base_url = "http://XXXXXXXXXXXX:YYYYYYYYYY@ROUTERS-IP-ADDRESS/WLG_adv.htm"            # Place your login:password here:
driver.get(base_url)
# Wifi click
wifi_button = driver.find_elements_by_xpath("//input[@name='enable_ap' and @value='enable_ap']")[0]
wifi_button.click()
# Apply click
apply_button = driver.find_element_by_xpath("//form[@id='target']/table[@class='subhead2-table']//button[@name='Apply']/span[@class='roundleft_apply']")
apply_button.click()
# Closing page (don't worry, it will complete the task, even when it's closed fast.
driver.stop_client()
driver.close()

最新更新