Python论坛  - 讨论区

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

2007年01月19日 星期五 13:21

email在gzemail.cn email在gzemail.cn
星期五 一月 19 13:21:13 HKT 2007

一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070119/14bebc39/attachment.html 

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

2007年01月22日 星期一 01:09

Huang You Gong hygool在gmail.com
星期一 一月 22 01:09:49 HKT 2007

你的TARGET是不是设置为http://www.tianya.cn
尝试改成http://www1.tianya.cn/default.asp
我测试过了,是可行的

On 1/19/07, email at gzemail.cn <email at gzemail.cn> wrote:
>
>  尝试过不行,有报错。报错如下:请指正,谢谢!
>
>  "C:\Program Files\python\python.exe" -u "D:\tianyaamy\login.py"
> Traceback (most recent call last):
>   File "D:\tianyaamy\login.py", line 41, in 
>     main()
>   File "D:\tianyaamy\login.py", line 29, in main
>     response = urllib2.urlopen( TARGET, line )
>   File "C:\Program Files\python\lib\urllib2.py", line 121, in urlopen
>     return _opener.open(url, data)
>   File "C:\Program Files\python\lib\urllib2.py", line 380, in open
>     response = meth(req, response)
>   File "C:\Program Files\python\lib\urllib2.py", line 491, in
> http_response
>     'http', request, response, code, msg, hdrs)
>   File "C:\Program Files\python\lib\urllib2.py", line 418, in error
>     return self._call_chain(*args)
>   File "C:\Program Files\python\lib\urllib2.py", line 353, in _call_chain
>     result = func(*args)
>   File "C:\Program Files\python\lib\urllib2.py", line 499, in
> http_error_default
>     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
> urllib2.HTTPError: HTTP Error 401: Unauthorized
>
>
>  ------------------------------
> *发件人: *"Huang You Gong"
> *日期: *Thu, 18 Jan 2007 18:45:52 +0800
> *收件人: *python-chinese at lists.python.cn
> *主题: *Re: [python-chinese] 关于cookie的问题
> 贴个小例子吧,具体教程也没有,啃英文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
>
>
> _______________________________________________
> 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/20070122/38df86f7/attachment.html 

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号