import os import requests import tkinter.messagebox import execjs import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC def login666(): # check wifi cmd = 'netsh wlan show interfaces' out=os.popen(cmd) cmd_ret = out.read() wifi = '' if cmd_ret: data = cmd_ret.split('\n') if data: for x in data: if x.strip().startswith('SSID'): wifi = x[x.index(':')+1:].strip() print('----------'+wifi+'----------') if wifi or True: # if True: url='http://6.6.6.6/login.jsp' option = webdriver.ChromeOptions() # option.add_argument('disable-infobars') # option.add_argument('user-data-dir=C:\\python37\\profile') driver = webdriver.Chrome() driver.get(url) #try: button = WebDriverWait(driver,10,1).until(EC.visibility_of_element_located((By.ID,'password_submitBtn'))) user = WebDriverWait(driver,10,1).until(EC.visibility_of_element_located((By.ID,'password_name'))) pwd = WebDriverWait(driver,10,1).until(EC.visibility_of_element_located((By.ID,'password_pwd'))) user.send_keys('abc') pwd.send_keys('bbb') # button.submit() button.click() #except: # print('get element error') #finally: driver.close() else: tkinter.messagebox.showinfo('info ','on find WIFI') if __name__ == '__main__': login666()
执行js
import execjs
jsfile = ''' function do_encrypt_rc4(src, passwd) { passwd = passwd + ''; var i, j = 0, a = 0, b = 0, c = 0, temp; var plen = passwd.length, size = src.length; var key = Array(256); //int var sbox = Array(256); //int var output = Array(size); //code of data for (i = 0; i < 256; i++) { key[i] = passwd.charCodeAt(i % plen); sbox[i] = i; } for (i = 0; i < 256; i++) { j = (j + sbox[i] + key[i]) % 256; temp = sbox[i]; sbox[i] = sbox[j]; sbox[j] = temp; } for (i = 0; i < size; i++) { a = (a + 1) % 256; b = (b + sbox[a]) % 256; temp = sbox[a]; sbox[a] = sbox[b]; sbox[b] = temp; c = (sbox[a] + sbox[b]) % 256; temp = src.charCodeAt(i) ^ sbox[c];//String.fromCharCode(src.charCodeAt(i) ^ sbox[c]); temp = temp.toString(16); if (temp.length === 1) { temp = '0' + temp; } else if (temp.length === 0) { temp = '00'; } output[i] = temp; } return output.join(''); } ''' TIMESTAMP=''' +(new Date()) + '' ''' USERNAME = 'abc' PASSWORD = 'def' def get_pass(pwd): ts = execjs.eval(TIMESTAMP) npwd = execjs.compile(jsfile).call('do_encrypt_rc4',pwd,ts) return ts,npwd
按钮提交
# 方法1:直接调用click()
a.click()
# 方法2:调用execute_script()
driver.execute_script("arguments[0].click();", a)
# 方法3:调用webdriver控制
webdriver.ActionChains(driver).move_to_element(a).click(a).perform()
配置selenium
http://npm.taobao.org/mirrors/chromedriver/
存放位置,和chrome.exe放置一起
C:\Program Files (x86)\Google\Chrome\Application
from selenium import webdriver
d=webdriver.Chrome()
d.close()
安装execjs
pip install PyExecJS