使用Cookijar完成模拟登录
本博文爬取实例为内部网站,请sduter使用本人账号替换*********(学号),***(姓名)进行登录
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
url = "http://210.44.176.97/datajudge/login.aspx"
driver = webdriver.Edge()
driver.get(url)
username_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@id='txtUser']"))
)
password_input = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[@id='txtPass']"))
)
username_input.send_keys("*********")
password_input.send_keys("***")
login_button = driver.find_element(By.XPATH, "//input[@id='btnLogin']")
login_button.click()
print(driver.page_source)
driver.quit()