Grab
0.6.41
  • Grab Installation
  • Testing Grab Framework
  • Grab Quickstart
  • Request Methods
  • Setting up the Grab Request
  • Grab Settings
  • Debugging
  • Work with HTTP Headers
  • Redirect Handling
  • Form Processing
  • Network Errors Handling
  • HTML Document Encoding
  • Cookie Support
    • Custom Cookies
  • Proxy Server Support
  • Searching the response body
  • Work With Network Response
  • Network Transport
  • What is Grab::Spider?
  • Task Object
  • Task Queue
  • Spider Error Handling
  • Explanation
  • API Reference
Grab
  • Cookie Support
  • View page source

Cookie Support

By default, Grab automatically handles all cookies it receives from the remote server. Grab remembers all cookies and sends them back in future requests. That allows you to easily implement scripts that log in to some site and then do some activity in a member-only area. If you do not want Grab to automatically process cookies, use reuse_cookies option to disable it.

Custom Cookies

To send some custom cookies, use the cookies option. The value of that option should be a dict. When you specify some cookies with cookies option and then fire network request, all specified cookies are bound to the hostname of the request.

Internally Grab instance stores cookies in http.cookiejar:CookieJar instance.

It is important to understand that Response object contains only cookies has been provided by the server in recent HTTP response. If you need all session cookies use “Grab:cookies” attribute.

If you want more granular control on custom cookies, you can use the grab.util.cookies.create_cookie function to create Cookie object and add its to Grab instance:

>>> from grab.util.cookies import create_cookie
>>> g = Grab()
>>> g.cookies.set_cookie(create_cookie(name='foo', value='bar', domain='yandex.ru', path='/host'))
Previous Next

© Copyright 2015 – 2023, Gregory Petukhov.

Built with Sphinx using a theme provided by Read the Docs.