python selenium练习
2022/4/22 14:13:04
本文主要是介绍python selenium练习,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import time from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By # 实例化driver对象 driver = webdriver.Chrome() # 窗口最大化 driver.maximize_window() driver.get('https://weibo.com/') # 输入账号 username = WebDriverWait(driver, 20, 0.5).until(EC.presence_of_element_located((By.ID, 'loginname'))) username.send_keys('') time.sleep(1) # 输入密码 password = driver.find_element_by_name('password') password.send_keys('') time.sleep(1) # 登录 submit_elements = driver.find_element(By.XPATH, '//*[@class="W_btn_a btn_32px"]') try: webdriver.ActionChains(driver).move_to_element(submit_elements).click().perform() time.sleep(2) # driver.quit() print(driver.page_source) except: print('登录失败,需要验证码')
这篇关于python selenium练习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享