用到火狐的webdriver有点麻烦。
1.首先要去载geckodriver-v0.21.0-win64
地址:https://github.com/mozilla/geckodriver/releases
2.然后将gecodriver.exe放到和python.exe一个目录下
3.接着配置环境变量,将火狐安装目录C:\Program Files (x86)\Mozilla Firefox也配置到环境变量path中
'''
from selenium import webdriver
import time
from urllib.request import urlopen
from bs4 import BeautifulSoup
def auto_login():
username = "admin"
password = "admin"
url ="http://10.96.1.50:8089/spc/spc_logonPage.do"
brower = webdriver.Firefox()
brower.get(url)
time.sleep(3)
brower.find_element_by_name('username').send_keys(username)
brower.find_element_by_id('password').send_keys(password)
brower.find_element_by_name('Login').click()
time.sleep(3)
brower.find_element_by_xpath(".//*[@id='cssmenu']/ul/li[8]").click() # 登录
time.sleep(2)
brower.close()
if name == 'main':
for i in range(1,10):
auto_login()
'''
网友评论