2007年01月18日 星期四 18:45
贴个小例子吧,具体教程也没有,啃英文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
Zeuux © 2025
京ICP备05028076号