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练习的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程