Grab
latest
  • 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
  • Docs »
  • Cookie Support
  • Edit on GitHub

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'))
Next Previous

© Copyright 2015 – 2023, Gregory Petukhov Revision 35e44c24.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: latest
Versions
latest
stable
v0.6.41-doc
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.