简体   繁体   English

使用机械化导入Cookie

[英]Importing Cookies with Mechanize

(Using Python 2.7, with Mechanize) (将Python 2.7与Mechanize一起使用)

Let's say I have a cookie on Twitter, named auth_token and it's Value is: ABC123 . 假设我在Twitter上有一个名为auth_token的cookie,其值是: ABC123

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

How do tell Mechanize to import this Cookie? 如何告诉Mechanize导入此Cookie? I've heard about Cookielib but I am not sure how to use it. 我听说过Cookielib但不确定如何使用它。 I looked it up, but I've no clue how to set this up with Mechanize . 我查了一下,但是不知道如何用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 为什么不将其作为HTTP标头传递

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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