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

猜你喜欢

转载自www.cnblogs.com/sanmubird/p/9208877.html