使用selenium自动化登录csdn
代码:
import selenium
from selenium import webdriver
from selenium.webdriver.common import keys
import time
driver = webdriver.Firefox()
driver.get("https://passport.csdn.net/login")
time.sleep(3)
element = driver.find_element_by_class_name('text-tab')
element = element.find_element_by_xpath('//*[@id="app"]/div/div/div/div[2]/div[2]/ul/li[1]')
element.click()
time.sleep(3)
elementuser = element.find_element_by_xpath('//*[@id="all"]')
elementuser.send_keys('xxxxxx')#用户名
elementpassword = element.find_element_by_xpath('//*[@id="password-number"]')
elementpassword.send_keys('xxxxxx')#密码
button = element.find_element_by_xpath('//*[@id="app"]/div/div/div/div[2]/div[2]/form/div/div[6]/div/button')
time.sleep(3)
button.click()
time.sleep(10)
print(driver.page_source)