Developed by GrabLab
Grab
0.6
  • Grab Installation
  • Testing Grab Framework
  • Grab Quickstart
  • Request Methods
  • Setting up the Grab Request
  • Grab Settings
  • Debugging
  • Work with HTTP Headers
  • Processing the Response Body
  • File Uploading
  • Redirect Handling
  • Form Processing
  • Network Errors Handling
  • HTML Document Charset
  • Cookie Support
    • Custom Cookies
    • Loading/dumping cookies
    • Permanent file to load/store cookies
  • Proxy Server Support
  • Searching the response body
  • Pycurl Tips
  • Work With Network Response
  • Network Transport
  • What is Grab::Spider?
  • Task Object
  • Task Queue
  • Spider Cache
  • Spider Error Handling
  • Spider Transport
  • Module grab.base
  • Module grab.error
  • Module grab.cookie
  • Module grab.spider
  • Module grab.document
  • Module grab.spider.task
Grab
  • GrabLab »
  • Docs »
  • 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. If you want more granular control on custom cookies, you can use the grab.cookies cookie manager to specify a cookie with any attributes you want:

>>> g = Grab()
>>> g.cookies.set(name='foo', value='bar', domain='yandex.ru', path='/host')

Loading/dumping cookies¶

To dump current cookies to a file, use grab.cookie.CookieManager.save_to_file().

To load cookies from a file, use grab.cookie.CookieManager.load_from_file().

Permanent file to load/store cookies¶

With the cookiefile option, you can specify the path to the file that Grab will use to store/load cookies for each request. Grab will load any cookies from that file before each network request, and after a response is received Grab will save all cookies to that file.

More details about grab.cookies you can get in API grab.cookie

Next Previous

© Copyright 2015, Gregory Petukhov

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

Developed by GrabLab - web scraping and data processing services.

He also does web scraping: www.imscraping.ninja.