使用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使用calendar输出指定年份全年日历的方法

本文实例讲述了python使用calendar输出指定年份全年日历的方法。分享给大家供大家参考。具体实现方法如下: import calendar print "Show a giv...

python3 深浅copy对比详解

一、赋值对比 1、列表 l1 = [1,2,3] l2 = l1 l1.append('a') print(l1,l2) #[1, 2, 3, 'a'] [1, 2,...

使用Python编写Prometheus监控的方法

要使用python编写Prometheus监控,需要你先开启Prometheus集群。可以参考/post/148895.htm 安装。在python中实现服务器端。在Prometheus...

Python做智能家居温湿度报警系统

Python做智能家居温湿度报警系统

物联网技术开创了一个智慧城市的新时代,从智能摄像头到部署各种传感器,以此对城市各种数据进行收集,并经云端AI技术处理后,有助于提高对交通和街道等城市公共管理能力;物联网的发展也为智能家居...

对python周期性定时器的示例详解

一、用thread实现定时器 py_timer.py文件 #!/usr/bin/python #coding:utf-8 import threading import os im...