我使用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','eyJfZmxhc2hlcyI6W3siIHQiOlsibWVzc2FnZSIsIlBsZWFzZSBsb2cgaW4gdG8gYWNjZXNzIHRoaXMgcGFnZS4iXX1dLCJFZJQQB1ZNQZBQJBQJBQJBQJBQJJZQJBQJJJJQJBQJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ)
答案 0 :(得分:1)
我知道了。由于使用Flask,我应该在python中使用request.cookie
来检索cookie。