python人人网登录应用实例
2023-06-13 09:15:46 时间
本文实例讲述了python人人网登录应用的实现方法,分享给大家供大家参考。
具体方法如下:
importre importurllib importurllib2 importcookielib importdatetime importtime fromurllib2importURLError,HTTPError #第一个参数为日志文件,第二个参数为用户名,第三个参数为密码 defrenren_login(logfile,username,password): logfile.write(str(datetime.datetime.now())+"renren/r/n") cj=cookielib.CookieJar() post_data=urllib.urlencode( {"email":username, "password":password, } ) path="http://www.renren.com/PLogin.do" opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) req=urllib2.Request(path,post_data) try: conn=urllib2.urlopen(req) exceptURLError,e: print"URLError" logfile.write("URLError:"+str(e.code)+"/r/n")#http://www.renren.com/SysHome.do returnFalse exceptHTTPError,e: logfile.write("HTTPError:"+e.reason+"/r/n") returnFalse ifconn.geturl()=="http://www.renren.com/home": print"success" logfile.write("Taskfinished/r/n") returnconn.read() else: print"TaskFailed" logfile.write("Taskfailed/r/n") #登录成功,返回整个页面的代码 file_object=open("log.txt","w") login_index=renren_login(file_object,"xxxxxx","xxxx")
希望本文所述对大家的Python程序设计有所帮助。
相关文章
- python hashlib_Python hashlib模块实例使用详解
- python监控网页内容变化_使用Python监控文件内容变化代码实例
- python表情代码_Python实现表情包的代码实例[通俗易懂]
- Python-OpenCV,基于标准文档的实例(二)
- lambda python表达式_Python的条件表达式和lambda表达式实例
- Python 冒泡排序_python
- python程序化交易实例-用 Python 实现你的量化交易策略「建议收藏」
- python encoding=utf-8_python以utf8打印字符串
- 如何利用python读excel数据_python在excel应用实例
- Python将数据写入txt文件_python将内容写入txt文件
- pycharm如何调试python程序_Pycharm断点调试Python程序的步骤方法
- 小试Python(二)
- 【错误记录】PyCharm 运行 Python 程序报错 ( PEP 8: W292 no newline at end of file )
- Python面向对象编程-类和对象-实例变量和类变量
- python-Python与SQLite数据库-处理SQLite查询结果(一)
- python-Python与MongoDB数据库-使用Python执行MongoDB查询(二)
- Python使用platform库获取系统信息:操作系统信息、硬件信息、python环境信息
- Python学习:6.python内置函数详解编程语言
- Python在连接MSSQL数据库中的应用(python连mssql)
- Python连接MySQL数据库:初学者指南(python入mysql)
- 从 Python 连接到 MySQL:实现更多强大的数据库应用(python和mysql)
- python发送邮件的实例代码(支持html、图片、附件)
- python双向链表实现实例代码
- Python设计模式之代理模式实例