selenium模拟登录网站

 

import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By

browser = webdriver.Edge()
browser.maximize_window()
url = "https://m.xiaoshuopu.com/user/login.html"
browser.get(url)

username_input = browser.find_element(By.XPATH, '//input[@id="username"]')
username_input.send_keys('xxx')
password_input = browser.find_element(By.XPATH, '//input[@id="password"]')
password_input.send_keys('xxx')

login_input = browser.find_element(By.XPATH, '//input[@class="login_in"]')
login_input.click()

selenium_cookie = browser.get_cookies()
print(selenium_cookie)
time.sleep(10)
browser.quit()

requests_cookie = {cookie['name']:cookie['value'] for cookie in selenium_cookie}
print(requests_cookie)

response = requests.get(url, cookies=requests_cookie)
print(response.text)

 

posted @ 2024-05-30 16:56  宝山方圆  阅读(42)  评论(0编辑  收藏  举报