== 测试环境:
- Selenium:
pip config set global.index-url --site https://pypi.tuna.tsinghua.edu.cn/simple
pip install selenium hashlib xlrd xlwt pandas numpy hashlib
#chromedriver for version>
解压chromedriver文件,放置chrome的安装目录下
https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/119.0.6045.21/win64/chromedriver-win64.zip
global driver # 设置全局变量
chromedriver_path =r"C:\Users\AppData\Local\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chromedriver_path)
driver.get("https://baidu.com/")
#firefox dirver geckodriver
解压geckodriver文件,放置firefox的安装目录下
https://mirrors.huaweicloud.com/geckodriver/v0.34.0/geckodriver-v0.34.0-win64.zip
- python38 + anaconda +Jupyter notebook
=== 参考文章 :
b ): Firefox 添加 selenium ID
第一步:打开火狐浏览器,找到最右边的菜单,选择附加组件,如图所示
找到selenium IDE添加到Firefox,进行安装;
解决find_element_by_id方法被弃用
https://blog.csdn.net/alijunshan/article/details/128730615
===code
import hashlib
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
#webdriver.Firefox(executable_path="C:/tmp/geckodriver.exe")
login_url = 'https://www.ybm100.com/login/login.htm' # 登录页面的URL
url=login_url
driver = webdriver.Firefox()
#driver = webdriver.Firefox(executable_path="C:/tmp/geckodriver.exe")
#driver.get('https://www.baidu.com')
driver.get(url)
#driver.find_element_by_xpath("//input[@id='kw']").send_keys("selenium")
#driver.find_element_by_xpath("//input[@id='su']").click()
driver.maximize_window()
#元素定位用户名输入框
username=driver.find_element(By.ID,"inputPhone")
#输入用户名
username.send_keys("xxxxx")
#元素定位密码输入框
password=driver.find_element(By.ID,"inputPassword")
pstring = "xxx"
创建MD5对象
hash_object = hashlib.md5()
更新MD5对象,传入要加密的字符串
hash_object.update(pstring.encode())
获取加密后的字符串
md5_str = hash_object.hexdigest()
#输入密码
password.send_keys(md5_str)
driver.find_element(By.ID,"agreement").click()
#元素定位登录按钮
#login=driver.find_element(By.CLASS_NAME,"sui-btn btn-primary")
login=driver.find_element(By.CLASS_NAME,"sui-btn")
#点击登录
login.click()
#等待1s
sleep(10)
版权归原作者 3c0755 所有, 如有侵权,请联系我们删除。