python requests 包 使用

1: 发送带 cookie 的 请求

resp = requests.get(self.url_item_list_first_page, cookies=self.cookies)
>>> url = 'http://httpbin.org/cookies'
>>> cookies = dict(cookies_are='working')

>>> r = requests.get(url, cookies=cookies)
>>> r.text
'{"cookies": {"cookies_are": "working"}}'
>>> jar = requests.cookies.RequestsCookieJar()
>>> jar.set('tasty_cookie', 'yum', domain='httpbin.org', path='/cookies')
>>> jar.set('gross_cookie', 'blech', domain='httpbin.org', path='/elsewhere')
>>> url = 'http://httpbin.org/cookies'
>>> r = requests.get(url, cookies=jar)
>>> r.text
'{"cookies": {"tasty_cookie": "yum"}}'

官网源码: http://docs.python-requests.org/zh_CN/latest/user/quickstart.html#cookie

posted @ 2018-06-21 14:26  三目鸟  阅读(235)  评论(0编辑  收藏  举报