import requestscookies = [{u'domain': u'academics.vit.ac.in',u'name': u'ASPSESSIONIDAEQDTQRB',u'value': u'ADGIJGJDDGLFIIOCEZJHJCGC',u'expiry': None,u'path': u'/',u'secure': True}]response = requests.get(url2,cookies=cookies)
给我以下例外:
Traceback (most recent call last): file "F:\PYTHON\python_scripts\cookies\cookies3.py",line 23,in <module> response = requests.get(url2,cookies=cookies) file "C:\Python27\lib\site-packages\requests\API.py",line 68,in get return request('get',url,**kwargs)<br/> file "C:\Python27\lib\site-packages\requests\sessions.py",line 450,in request prep = self.prepare_request(req) cookies = cookiejar_from_dict(cookies) file "C:\Python27\lib\site-packages\requests\cookies.py",line 439,in cookiejar_from_dict cookiejar.set_cookie(create_cookie(name,cookie_dict[name]))TypeError: List indices must be integers,not dict解决方法 首先,您必须从驱动程序实例获取cookie:
cookies = driver.get_cookies()
这将为您的会话返回set of cookie dictionaries.
接下来,在请求中设置这些cookie:
s = requests.Session()for cookie in cookies: s.cookies.set(cookie['name'],cookie['value'])总结
以上是内存溢出为你收集整理的如何将会话和Cookie从Selenium浏览器加载到Python中的请求库?全部内容,希望文章能够帮你解决如何将会话和Cookie从Selenium浏览器加载到Python中的请求库?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)