Python cant access all of cookies that are appearing in Chrome inspector

问题: I created the cookies using JavaScript, the page is then reloaded and I retrieve the cookies with Python, but the only cookie that is retrieved is the session cookie. Add...

问题:

I created the cookies using JavaScript, the page is then reloaded and I retrieve the cookies with Python, but the only cookie that is retrieved is the session cookie.

Adding Cookie:

 function changeFeatures() {
        document.cookie = "byteName=" + document.getElementById("byteName").value+"; path=/";
        document.cookie = "byteDescription=" + document.getElementById("byteDescription").value+"; path=/";
        document.cookie = "byteType=" + document.getElementById("byteType").value+"; path=/";
        document.cookie = "byteEndian=" + document.getElementById("byteEndian").value+"; path=/";
        document.cookie = "byteParent=" + document.getElementById("byteParent").value+"; path=/";
        document.cookie = "byteOffset=" + document.getElementById("byteOffset").value+"; path=/";
        document.cookie = "byteLength=" + document.getElementById("byteLength").value+"; path=/";

        location.reload();
    }

Retrieving Cookie:

 import requests
    r = requests.get('http://localhost:5000/)
    print(r)
    c = r.cookies
    print(c)
    i = c.items()
    print(i)

r prints:

Response [200]

c prints:

RequestsCookieJar[]

i prints:

[('session', 'eyJfZmxhc2hlcyI6W3siIHQiOlsibWVzc2FnZSIsIlBsZWFzZSBsb2cgaW4gdG8gYWNjZXNzIHRoaXMgcGFnZS4iXX1dLCJfZnJlc2giOmZhbHNlfQ.XJEbzA.2QOTc9iPNBD_RSEVgAdnvR36chE')]

Picture of Chrome cookies enter image description here


回答1:

I figured it out. I was supposed to use request.cookie in python to retrieve the cookie since I'm using Flask.

  • 发表于 2019-03-20 20:54
  • 阅读 ( 208 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除