Python论坛  - 讨论区

标题:[python-chinese] 关于cookie的问题

2007年01月18日 星期四 18:45

Huang You Gong hygool在gmail.com
星期四 一月 18 18:45:52 HKT 2007

贴个小例子吧,具体教程也没有,啃英文manual是王道


*#!/usr/bin/python*

*import urllib
import urllib2
import cookielib*

*TARGET = 'http://bbs.xmu.edu.cn/bbslogin.php'
USERID = 'id'
USERNAME = 'bone'
PASSWDID = 'passwd'
PASSWORD = '123456789'*

*def main():*

*    authinfo = urllib2.HTTPBasicAuthHandler()
    cookie = cookielib.CookieJar()
    cp = urllib2.HTTPCookieProcessor( cookie )

    opener = urllib2.build_opener( cp )
    urllib2.install_opener( opener )*

*    line = urllib.urlencode( { USERID : USERNAME , PASSWDID : PASSWORD } )
    response = urllib2.urlopen( TARGET, line )
    lines = response.read()*

*    f = open( "pagecode.txt", "w" )
    for line in lines:
        f.write( line )
    f.close()

    response.close()*

*main()*



On 1/18/07, Mr.李 <py.7 at 163.com> wrote:
>
> 大家好!
>
>
> 偶刚开始学python,最近想通过python访问需要登录后才可以访问的网页,据说需要通过cookies来操作,请教各位高人,有没有关于cookielib,
> urllib2的中文教程呢,应该怎样应用,麻烦大家了``
>
>
>
>
>> 礼!
>
>
> 李李
> 2007-01-18
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
Best Regards,
Huang You Gong
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070118/54af61b4/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号