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

上一篇:python requests.request 和session.request区别究竟在哪里


下一篇:java如何调用另一个包里面的类