小编Yon*_*eng的帖子

如何在Python 3中使用Cookie?

我想使用从Chrome浏览器复制的Cookie,但会出错。

import urllib.request
import  re

def  open_url(url):
header={"User-Agent":r'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'}
Cookies={'Cookie':r"xxxxx"}
Request=urllib.request.Request(url=url,headers=Cookies)
response=urllib.request.urlopen(Request,timeout=100)
return  response.read().decode("utf-8")
Run Code Online (Sandbox Code Playgroud)

我的代码在哪里出错?那是headers = Cookies吗?

python python-3.x

5
推荐指数
2
解决办法
8257
查看次数

标签 统计

python ×1

python-3.x ×1