Python无法访问Chrome检查器中显示的所有cookie

时间:2019-03-19 16:57:57

标签: javascript python cookies

我使用JavaScript创建了cookie,然后重新加载了页面,并使用Python检索了cookie,但是唯一检索到的cookie是会话cookie。

添加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();
    }

获取Cookie:

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

r张照片:

  

响应[200]

c打印:

  

RequestsCookieJar []

我打印:

  

[('session','eyJfZmxhc2hlcyI6W3siIHQiOlsibWVzc2FnZSIsIlBsZWF​​zZSBsb2cgaW4gdG8gYWNjZXNzIHRoaXMgcGFnZS4iXX1dLCJFZJQQB1ZNQZBQJBQJBQJBQJBQJJZQJBQJJJJQJBQJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ)

Chrome Cookie的图片 enter image description here

1 个答案:

答案 0 :(得分:1)

我知道了。由于使用Flask,我应该在python中使用request.cookie来检索cookie。