Skip to content

Instantly share code, notes, and snippets.

@tanaikech
Created January 2, 2017 02:26
Show Gist options
  • Save tanaikech/5c2055094788844eb9fbf6b4c8b91664 to your computer and use it in GitHub Desktop.
Save tanaikech/5c2055094788844eb9fbf6b4c8b91664 to your computer and use it in GitHub Desktop.
Python, Selenium, PhantomJSを使ってルータを再起動する ref: http://qiita.com/tanaike/items/8e8dbf8f04abe62ca7b7
http://ユーザ名:パスワード@ルータのIPアドレス
from bs4 import BeautifulSoup
from selenium import webdriver
class pr500mi(object):
"""This is for PR-500MI."""
def __init__(self):
self.baseurl = 'http://ユーザ名:パスワード@ルータのIPアドレス'
self.driver = webdriver.PhantomJS()
def getip(self):
getipurl = self.baseurl + '/ntt/information/fifth/current/'
self.driver.get(getipurl)
html = self.driver.page_source.encode('utf-8')
soup = BeautifulSoup(html, 'lxml')
ip = soup.findAll(class_='section')[6].findAll('td')
return (ip[1].get_text(), ip[21].get_text()) # ipv4, ipv6
def reboot(self):
rebooturl = self.baseurl + '/ntt/userMaintenance/reboot/'
self.driver.get(rebooturl)
self.driver.find_element_by_id('REBOOT').click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment