python項目之 路由器抓取器

路由器抓取器

使用的庫

selenium
firefox瀏覽器

路由器型號

FAST 某型號的

思路

本來準備使用requests的,然後抓取的網頁沒有信息,原因是網頁是動態網頁,數據不能被抓取。
最後選取selenium庫實現的,模擬網頁登陸。
抓取到外網 mac地址和ip,用戶列表,然後保存成文本。

可以查到誰在用網絡,防蹭網

代碼部分

#coding:utf-8
import urllib.request as res
import requests
import time
import datetime
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains 
from selenium.webdriver.common.keys import Keys

MIMA = '填入你自己的密碼'

url_s = 'http://192.168.11.1/main/status.htm?_='

def sp(int):
    time.sleep(int)

ss = str(int(time.time()//1))+'012'
print(ss)

browser = webdriver.Firefox()
browser.get('http://192.168.11.1')
sp(1)
browser.find_element_by_id('pcPassword').send_keys(MIMA)
browser.find_element_by_id('logIn').click()
sp(1)
wanmac = browser.find_element_by_id('wanmac')
print('wan MAC:')
str_wanmac = wanmac.text
print(wanmac.text)
wanip = browser.find_element_by_id('wanip')
print('wan IP:')
str_wanip = wanip.text
print(wanip.text)

browser.find_element_by_id('menu_dhcp').click()
sp(1)
browser.find_element_by_id('menu_clientlist').click()
sp(2)
#browser.get(dhtp+ss)
hostTbl = browser.find_element_by_id('hostTbl')
str_client = hostTbl.text
print(str_client)

now = datetime.datetime.now()
str_time = now.strftime("%Y_%m_%d_%H_%M_%S")
with open(str_time+'.txt','w') as f:
    f.write(str_time+'\n\n')
    f.write('wan MAC:'+str_wanmac+'\n')
    f.write('wan IP:'+str_wanip+'\n\n')
    f.write(str_client+'\n')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章