转自:https://www.cnblogs.com/luckiness/p/13406932.html文章来源地址https://www.toymoban.com/news/detail-829040.html
from selenium import webdriver
from lxml import etree
import requests
driver=webdriver.Chrome()
driver.get("https://so.gushiwen.cn/user/login.aspx?from=http://so.gushiwen.cn/user/collect.aspx")
账号=driver.find_element_by_xpath('//*[@id="email"]')
账号.send_keys("xxxxx")
密码=driver.find_element_by_xpath('//*[@id="pwd"]')
密码.send_keys("lhxxx")
验证码=driver.find_element_by_xpath('//*[@id="code"]')
a=input("请输入验证码:")
验证码.send_keys(a)
登录=driver.find_element_by_xpath('//*[@id="denglu"]')
登录.click()
headers={"user-agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36"}
#获取当前网址
url=driver.current_url
#获取cookies
cookies_1=driver.get_cookies()
cookies={}
for i in cookies_1:
cookies[i["name"]]=i["value"]
print(cookies)
response=requests.get(url,headers=headers,cookies=cookies).text
content=etree.HTML(response)
c=content.xpath('//*[@id="mainSearch"]/div[3]/div[1]/div[1]/a/text()')[0]
print(c)
文章来源:https://www.toymoban.com/news/detail-829040.html
到了这里,关于【Python】selenium把cookies传递给requests的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!