使用python实现baidu hi自动登录的代码

yipeiwu_com6年前Python基础
复制代码 代码如下:

# _*_ coding:utf-8 _*_
# name login_baidu.py
import urllib,urllib2,httplib,cookielib
def auto_login_hi(url,name,pwd):
    url_hi="http://passport.baidu.com/?login"
    #设置cookie
    cookie=cookielib.CookieJar()
    cj=urllib2.HTTPCookieProcessor(cookie)
    #设置登录参数
    postdata=urllib.urlencode({'username':name,'password':pwd})
    #生成请求
    request=urllib2.Request(url_hi,postdata)
    #登录百度
    opener=urllib2.build_opener(cj)
    f=opener.open(request)
    print f
    #打开百度HI空间页面
    hi_html=opener.open(url)
    return hi_html
if __name__=='__main__':
    name='hjkll'
    password='11111111'
    url='http://hi.baidu.com/ewayfly'
    h=auto_login_hi(url,name,password)
    print h.read()

相关文章

python画图系列之个性化显示x轴区段文字的实例

python画图系列之个性化显示x轴区段文字的实例

今天在写一个研究生创新项目申报书时涉及到一个python画图问题,对于在x轴各个区段显示自定义的字符串有些疑问,特此记录。 界面如下所示: 代码如下所示: import matpl...

使用virtualenv创建Python环境及PyQT5环境配置的方法

使用virtualenv创建Python环境及PyQT5环境配置的方法

一、写在前面   从学 Python 的第一天起,我就知道了使用 pip 命令来安装包,从学习爬虫到学习 Web 开发,安装的库越来越多,从 requests 到 lxml,从 Djan...

把大数据数字口语化(python与js)两种实现

python 复制代码 代码如下:def fn(num):    '''    把数字口语化   ...

python检查指定文件是否存在的方法

本文实例讲述了python检查指定文件是否存在的方法。分享给大家供大家参考。具体如下: import os def file_exists(file_name): if os....

Python 迭代器工具包【推荐】

  原文:https://git.io/pytips   0x01 介绍了迭代器的概念,即定义了 __iter__() 和 __next__() 方法的对象,或者通过 yield 简化定...