[CPyUG] Python模拟登陆,POST数据并保存COOKIE等概念的详细讲解?

177 views
Skip to first unread message

张淳

unread,
Apr 26, 2011, 2:44:52 AM4/26/11
to pyth...@googlegroups.com
如题,想做python模拟登陆,需要post数据并取得返回的cookie,后面还要携带这些cookie进行get或post
google了一个多小时,看到了HTTPCookieProcessor,看到有用urllib2或者httplib做的,没有找到一篇系统讲解这些概念的文章
来此请教各位,系统的讲解下python模拟登陆的技术,谢谢!

lee Alexander

unread,
Apr 26, 2011, 2:48:14 AM4/26/11
to pyth...@googlegroups.com
你把http协议搞懂了就一法通万法通了,学习要掌握事务的本质而不是表面现象

--
来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
发言: pyth...@googlegroups.com
退订: python-cn+...@googlegroups.com (向此发空信即退!)
详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug
http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



--
Alexander.Li
+86 15308006505
mail: superp...@gmail.com/superp...@hotmail.com
site:http://alexander-lee.cnblogs.com

张淳

unread,
Apr 26, 2011, 3:17:34 AM4/26/11
to pyth...@googlegroups.com
那你搞通了吗,麻烦讲解一下

Shell Xu

unread,
Apr 26, 2011, 3:23:56 AM4/26/11
to pyth...@googlegroups.com
RTFM
http://www.ietf.org/rfc/rfc2616.txt
If u wanna more, maybe can read source of this.
http://eventlet.net/
or this, which written by me.
http://code.google.com/p/py-web-server/
无能者无所求,饱食而遨游,泛若不系之舟
blog: http://shell909090.com/blog/
twitter: http://twitter.com/shell909090

zeroq

unread,
Apr 26, 2011, 3:34:03 AM4/26/11
to pyth...@googlegroups.com
主要是get/set HTTP头,COOKIE啊、POST数据啊、URL啊等等都在这里面
详细讲解这些概念就去看HTTP协议吧

lee Alexander

unread,
Apr 26, 2011, 3:55:19 AM4/26/11
to pyth...@googlegroups.com
协议文档是公开的,http是开放的文本协议,相对来说是很简单的。

在 2011年4月26日 下午3:17,张淳 <zhan...@xiguaner.com>写道:

赵荣伟

unread,
Apr 26, 2011, 9:43:51 AM4/26/11
to pyth...@googlegroups.com
可以用python+curl实现,php版本的实现过,python我刚刚开始学.还不知道怎么弄:)
退订: python-cn+unsub...@googlegroups.com (向此发空信即退!)

详情: http://code.google.com/p/cpyug/wiki/PythonCn
严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
强烈: 建议使用技巧: 如何有效地报告Bug
http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html



体验网易邮箱2G超大附件,轻松发优质大电影、大照片,提速3倍!

dean forever

unread,
Apr 26, 2011, 10:01:24 PM4/26/11
to pyth...@googlegroups.com
http://caleng.iteye.com/blog/709150
看这个文章 吧 我试过用他去0点刷红包 挺好用 哈哈

> ________________________________
> 体验网易邮箱2G超大附件,轻松发优质大电影、大照片,提速3倍!
>

Scorponok Z

unread,
Apr 26, 2011, 10:33:28 PM4/26/11
to pyth...@googlegroups.com
诶,居然有cookielib这个库啊

范三山

unread,
Apr 26, 2011, 11:26:50 PM4/26/11
to pyth...@googlegroups.com
cookiejar = cookielib.MozillaCookieJar()
cookies = urllib2.HTTPCookieProcessor(cookiejar)
opener = urllib2.build_opener(self.cookies)

......

cookiejar.save(cookiepath)

下次要用的时候
cookiejar = cookielib.MozillaCookieJar()
cookiejar.load(path)

zong

unread,
Apr 27, 2011, 12:02:16 AM4/27/11
to pyth...@googlegroups.com
obmem.info/?p=476#comment-9846

我就是通过这个学到手的。 模拟登陆问题不大,麻烦在验证码。
HTTP协议是公开的,但是在Python中是如何实现和被支持的,这需要学习。

感谢 Obersver兄弟,看他的blog是享受。

2011/4/27 范三山 <vanse...@gmail.com>



--
++++++++++++++++++++++++++++++
搭建在GAE上的个人网站=> HomePage (只是一个雏形,一点点儿的慢慢打造中。)

Bill Liao

unread,
Apr 27, 2011, 12:11:18 AM4/27/11
to pyth...@googlegroups.com
现在很多登录貌似都涉及到由javascript生成验证信息(比如说新浪微博),不知道大家都怎么解决这种问题的。

>>>> 详情:  <http://code.google.com/p/cpyug/wiki/PythonCn>--
> ++++++++++++++++++++++++++++++搭建在GAE上的个人网站=> HomePage <http://www.sunshaozong.com> (只是一个雏形,一点点儿的慢慢打造中。)


>
>
>
>
>
>
> --
> 来自: python-cn`CPyUG`华蟒用户组(中文Python技术邮件列表)
> 发言: pyth...@googlegroups.com
> 退订: python-cn+...@googlegroups.com (向此发空信即退!)
> 详情: http://code.google.com/p/cpyug/wiki/PythonCn
> 严正: 理解列表! 智慧提问! http://wiki.woodpecker.org.cn/moin/AskForHelp
> 强烈: 建议使用技巧: 如何有效地报告Bug
> http://www.chiark.greenend.org.uk/%7Esgtatham/bugs-cn.html
>

--
*If the dream is BIG enough,the facts don't count!*

张淳

unread,
Apr 27, 2011, 2:15:43 AM4/27/11
to pyth...@googlegroups.com
感谢了!
再问个问题,如下代码:
cj = cookielib.CookieJar()
如何从cj中得到 HTTP Header 中Cookie那样的格式:'aaa=xxx; bbb=xxx; ccc=xxx'

Scorponok Z

unread,
Apr 27, 2011, 3:55:04 AM4/27/11
to pyth...@googlegroups.com
for cookie in cookiejar:
  print cookie.name, cookie.value

可以这样吗?

Scorponok Z

unread,
Apr 27, 2011, 3:55:35 AM4/27/11
to pyth...@googlegroups.com
没有直接的办法吧,勉强用这个自己组合了

张淳

unread,
Apr 27, 2011, 9:05:26 AM4/27/11
to pyth...@googlegroups.com
这个可以满足我的需求,谢谢!

han wu

unread,
Apr 27, 2011, 9:19:43 PM4/27/11
to pyth...@googlegroups.com
可以看看twill,好东西,谁用谁知道,嘿嘿

Zhang Jiawei

unread,
Apr 27, 2011, 10:48:35 PM4/27/11
to pyth...@googlegroups.com
还是很麻烦, twill 很久没更新。

han wu

unread,
Apr 28, 2011, 12:02:43 AM4/28/11
to pyth...@googlegroups.com
用selenium也可以,可以直接录制成python脚本

han wu

unread,
Apr 28, 2011, 12:08:40 AM4/28/11
to pyth...@googlegroups.com
还有mechanize,twill就是基于这个开发的

张淳

unread,
Apr 28, 2011, 2:41:26 AM4/28/11
to pyth...@googlegroups.com
我用了twill,很好使!
但是有个问题,看文档也没有明白:

含有多个form并且有多个submit(submit都没有name)时,调用submit的参数应该怎么指定?



在 2011年4月28日 上午9:19,han wu <jaso...@gmail.com>写道:

han wu

unread,
May 3, 2011, 3:24:17 AM5/3/11
to pyth...@googlegroups.com
用fv(formvalue)来指定

张淳

unread,
May 3, 2011, 8:35:42 PM5/3/11
to pyth...@googlegroups.com
我是说用submit怎么指定没有名字的form?
Reply all
Reply to author
Forward
0 new messages