Purpose
通过分析页面,实现校园网自动输入账号密码,点击登录的操作
Environment deployment
-
win10
Firefox 87 (64位)
python 3.9
-
install selenium
pip install selenium
- Install driver for firefox
Firefox driver download version address:
https://github.com/mozilla/geckodriver/releases
analysis page
-
Find the username input element of the HTML page and analyze the logic.
-
Look for password input elements
-
Analyze the js logic of the page
and find that there is a jseven
to display the hidden password boxSo selenium needs to implement the logic code requirements to click on the previous element to trigger the display #pwd element
implement logic code
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
from time import sleep
driver= webdriver.Firefox()
driver.get("http://10.8.2.2")
driver.set_window_size(895, 739)
# 方案一 利用tab自动输入密码后跳转到密码框
# driver.find_element(By.ID, "username").send_keys("user", Keys.TAB,"passwd")
# 方案二 分析代码原理,点击元素后触发原来的js,显示出密码框,之前是隐藏的
driver.find_element(By.ID, "username").send_keys("user")
driver.find_element(By.ID, "pwd_tip").click()
driver.find_element(By.ID, "pwd").send_keys("passwd")
driver.find_element(By.ID, "selectDisname").click()
driver.find_element(By.ID, "_service_2").click()
driver.find_element(By.ID, "loginLink_div").click()
demo video
Notice
This article is only published in the blog garden Billyme and CSDN horizen08 , and reprinting is not allowed. If you see this article anywhere, it is purely malicious misappropriation.