今天分享一个CSDN登录模块的登录场景
1.配置文件
CSDNconf.py:
from selenium import webdriver options = webdriver.ChromeOptions() options.binary_location = r"D:\Program Files\360\360se6\Application\360se.exe" # 360浏览器安装地址 driver = webdriver.Chrome(executable_path=r'D:\Python\Python311\chromedriver.exe',options=options)
2.登陆文件
CSDNlogin.py
from selenium.webdriver.common.by import By import CSDNconf class Login(): def login(self): CSDNconf.driver.get("https://passport.csdn.net/") CSDNconf.driver.maximize_window() #点击密码登录 CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[1]/span[4]").click() #输入用户名 CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/div/div[1]/div/input").send_keys("627168856@qq.com") #输入密码 CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/div/div[2]/div/input").send_keys("?love717") # 勾选我已阅读并同意 服务条款 和 隐私协议 CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/p/div/i").click() #点击登录按钮 CSDNconf.driver.find_element(By.XPATH,"/html/body/div[2]/div/div[2]/div[2]/div[2]/div/div[2]/div/div[4]/button").click()
3.执行文件
executeFile.py
import time import CSDNFBWZ import CSDNconf import CSDNlogin #fbwz=CSDNFBWZ.FBWZ() #fbwz.fb() lg=CSDNlogin.Login lg.login() time.sleep(10) CSDNconf.driver.quit()
执行executeFile.py