实战:模拟登录知乎网站(添加cookie)

from urllib import request

url = "https://www.zhihu.com/hot"
headers = {
	"user-agent": "从浏览器检查的network中复制user-agent的内容",
	"cookie":"用浏览器登录网站后,从network中复制cookie的内容"
}
rq = request.Request(url,headers=headers)
resp = request.urlopen(rq)
print(resp.read().decode('utf-8'))

你可能感兴趣的:(实战:模拟登录知乎网站(添加cookie))