简体   繁体   中英

Importing Cookies with Mechanize

(Using Python 2.7, with Mechanize)

Let's say I have a cookie on Twitter, named auth_token and it's Value is: ABC123 .

https://i.gyazo.com/de568907c939617c14a874696664aeeb.png

How do tell Mechanize to import this Cookie? I've heard about Cookielib but I am not sure how to use it. I looked it up, but I've no clue how to set this up with Mechanize .

If someone could help me out, that would be awesome! :)

import Cookie
import cookielib
cookiejar =cookielib.LWPCookieJar()

br = mechanize.Browser()
br.set_cookiejar(cookiejar)
cookie = cookielib.Cookie(auth_token='ABC123')
cookiejar.set_cookie(cookie)

Why not pass it as HTTP headers

br=mechanize.Browser()
br.addheaders = [('Cookie','name=value')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM