selenium登陆CSDN

import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
import uiautomation as auto
url = 'https://mp.csdn.net/mp_blog/manage/article'
account_number = '你的账号'
password = '你的密码'
option = webdriver.ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=option)
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument',
                       {'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'
                        })
driver.get(url)

# 窗口最大化,便于操作
driver.maximize_window()
time.sleep(2)
# /html/body/div[2]/div/div[2]/div[2]/div[1]/div[1]/div[1]/span[4]
driver.find_element(by=By.XPATH, value='/html/body/div[2]/div/div[2]/div[2]/div[1]/div[1]/div[1]/span[4]').click()
# time.sleep(2)
driver.find_element(by=By.XPATH, value='/html/body/div[2]/div/div[2]/div[2]/div[1]/div/div[2]/div/div[1]/div/input').send_keys(account_number)
driver.find_element(by=By.XPATH, value='/html/body/div[2]/div/div[2]/div[2]/div[1]/div/div[2]/div/div[2]/div/input').send_keys(password)

time.sleep(2)
login_page = auto.DocumentControl(Name="CSDN-专业IT技术社区-登录")
login_btn = login_page.ButtonControl(Name="登录")
login_btn.Click()

之前研究的,大家有需要的可以使用,目前使用账号密码还是可以登陆上的

你可能感兴趣的:(selenium,测试工具)