python的requests+selenium实现模拟登陆

import requests
from time import sleep
from selenium import webdriver
#chromePath = r'浏览器存放位置'
#wd = webdriver.Chrome(executable_path= chromePath) #构建浏览器
wd = webdriver.Chrome()
loginUrl = 'https://accounts.google.com'
wd.get(loginUrl) #进入登陆界面
wd.find_element_by_xpath('//*[@id="identifierId"]').send_keys(‘账号') #输入用户名
wd.find_element_by_xpath('//*[@id="identifierNext"]/content/span').click() #点击登陆
sleep(1)
wd.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys('密码') #输入密码
sleep(1)
wd.find_element_by_xpath('//*[@id="passwordNext"]/content/span').click() #点击登陆
req = requests.Session() #构建Session
cookies = wd.get_cookies() #导出cookie
for cookie in cookies:
    req.cookies.set(cookie['name'], cookie['value']) #转换cookies

猜你喜欢

转载自blog.csdn.net/weixin_33810006/article/details/90840739