Selenium Python-将Cookie从会话传输到Webdriver

时间:2019-01-29 12:07:53

标签: python selenium google-chrome webdriver python-requests

早上好。我正在尝试从requests.session传输cookie 到我的Chrome网络驱动程序。

我的代码如下:

import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

s=requests.session()
scraper=cfscrape.create_scraper(sess=s)

header={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"}


dataz={"login[email]": "", #my login data
    "login[password]": ""}


x=scraper.get("https://bstn.com")


y=scraper.post("https://www.bstn.com/einloggen", headers=header, data=dataz, allow_redirects=False)

print(y.cookies._cookies) 


driver=webdriver.Chrome()

driver.add_cookie(y)

driver.get("https://bstn.com/")```

The error I get is the following:
  ```  raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Response is not JSON serializable```

I hope that someone can help me fixing this error. My result that I expect is that I can run the script and continue my session in the browser... Thanks a lot

0 个答案:

没有答案