python模拟登录百度贴吧(百度贴吧登录)实例

时间:2023-11-20 14:30:56 


python模拟登录百度贴吧(百度贴吧登录)实例
 



# -*- coding:utf-8 -*-
# python3.3.3

import sys,time,re,urllib.parse,urllib.request,http.cookiejar,random,math,os.path,hashlib,json,binascii,threading

"""cookie"""
cookie=http.cookiejar.LWPCookieJar()
#cookie.load('f:/cookie.txt',True,True)
chandle=urllib.request.HTTPCookieProcessor(cookie)
"""获取数据"""
def getData(url):
    r=urllib.request.Request(url)
    opener=urllib.request.build_opener(chandle)
    u=opener.open(r)
    #chandle.cookiejar.save('f:/cookie.txt',True,True)
    data=u.read()
    try:
        data=data.decode('utf-8')
    except:
        data=data.decode('gbk','ignore')
    return data
def postData(url,data):
    data=urllib.parse.urlencode(data);data=bytes(data,'utf-8')
    r=urllib.request.Request(url,data)
    opener=urllib.request.build_opener(chandle)
    u=opener.open(r)
    #chandle.cookiejar.save('f:/cookie.txt',True,True)
    data=u.read()
    try:
        data=data.decode('utf-8')
    except:
        data=data.decode('gbk','ignore')
    return data
def login(name,pwd):
    url='http://www.baidu.com'
    getData(url)
    par={
        "apiver":'v3',
        "callback":'bd__cbs__oug2fy',
        "class":'login',
        "logintype":'dialogLogin',
        "tpl":'tb',
        "tt":'1385013373144'
    }
    url='https://passport.baidu.com/v2/api/?getapi&%s' % urllib.parse.urlencode(par)
    token=re.findall('"token" : "(.*?)"',getData(url))[0]
    par.update({"isphone":'false',"username":name,"token":token})
    url='https://passport.baidu.com/v2/api/?logincheck&?%s' % urllib.parse.urlencode(par)
    data={
        "charset":'GBK',
        "mem_pass":'on',
        "password":pwd,
        "ppui_logintime":'1612376',
        "quick_user":'0',
        "safeflg":'0',
        "splogin":'rate',
        "u":'http://tieba.baidu.com/'
    }
    url='https://passport.baidu.com/v2/api/?login'
    par.update(data)
    bdu=re.findall('hao123Param=(.*?)&',postData(url,par))[0]
    par={
        "bdu":bdu,
        "t":'1385013373144'
    }
    url='http://user.hao123.com/static/crossdomain.php?%s' % urllib.parse.urlencode(par)
    getData(url)
    print(json.loads(getData('http://tieba.baidu.com/f/user/json_userinfo')))
"""------输入帐号密码------"""
login('帐号','密码')


# -*- coding:utf-8 -*-
# python3.3.3

import sys,time,re,urllib.parse,urllib.request,http.cookiejar,random,math,os.path,hashlib,json,binascii,threading

"""cookie"""
cookie=http.cookiejar.LWPCookieJar()
#cookie.load('f:/cookie.txt',True,True)
chandle=urllib.request.HTTPCookieProcessor(cookie)
"""获取数据"""
def getData(url):
    r=urllib.request.Request(url)
    opener=urllib.request.build_opener(chandle)
    u=opener.open(r)
    #chandle.cookiejar.save('f:/cookie.txt',True,True)
    data=u.read()
    try:
        data=data.decode('utf-8')
    except:
        data=data.decode('gbk','ignore')
    return data
def postData(url,data):
    data=urllib.parse.urlencode(data);data=bytes(data,'utf-8')
    r=urllib.request.Request(url,data)
    opener=urllib.request.build_opener(chandle)
    u=opener.open(r)
    #chandle.cookiejar.save('f:/cookie.txt',True,True)
    data=u.read()
    try:
        data=data.decode('utf-8')
    except:
        data=data.decode('gbk','ignore')
    return data
def login(name,pwd):
    url='http://www.baidu.com'
    getData(url)
    par={
        "apiver":'v3',
        "callback":'bd__cbs__oug2fy',
        "class":'login',
        "logintype":'dialogLogin',
        "tpl":'tb',
        "tt":'1385013373144'
    }
    url='https://passport.baidu.com/v2/api/?getapi&%s' % urllib.parse.urlencode(par)
    token=re.findall('"token" : "(.*?)"',getData(url))[0]
    par.update({"isphone":'false',"username":name,"token":token})
    url='https://passport.baidu.com/v2/api/?logincheck&?%s' % urllib.parse.urlencode(par)
    data={
        "charset":'GBK',
        "mem_pass":'on',
        "password":pwd,
        "ppui_logintime":'1612376',
        "quick_user":'0',
        "safeflg":'0',
        "splogin":'rate',
        "u":'http://tieba.baidu.com/'
    }
    url='https://passport.baidu.com/v2/api/?login'
    par.update(data)
    bdu=re.findall('hao123Param=(.*?)&',postData(url,par))[0]
    par={
        "bdu":bdu,
        "t":'1385013373144'
    }
    url='http://user.hao123.com/static/crossdomain.php?%s' % urllib.parse.urlencode(par)
    getData(url)
    print(json.loads(getData('http://tieba.baidu.com/f/user/json_userinfo')))
"""------输入帐号密码------"""
login('帐号','密码')

标签:python模拟登录,百度贴吧登录
0
投稿

猜你喜欢

  • Python使用pyserial进行串口通信的实例

    2022-03-07 15:30:09
  • sina和265天气预报调用代码

    2007-11-19 13:32:00
  • python实现字符串和数字拼接

    2023-05-29 07:05:29
  • 13个你希望早点知道的实用WordPress SQL查询语句[译]

    2010-02-28 12:48:00
  • js 代码优化点滴记录

    2024-05-28 15:41:47
  • 简单谈谈python中的语句和语法

    2023-03-03 12:03:13
  • python如何调用现有的matlab函数

    2023-04-28 22:07:09
  • Python爬虫抓取技术的一些经验

    2021-06-09 12:02:23
  • MySQL优化之数据类型的使用

    2009-03-16 17:12:00
  • 用python写个博客迁移工具

    2023-06-09 05:13:14
  • Python中import导入不同目录的模块方法详解

    2021-04-08 02:37:08
  • 在Python 字典中一键对应多个值的实例

    2023-07-25 23:45:02
  • MySQL死锁的产生原因以及解决方案

    2024-01-26 16:11:40
  • php tpl模板引擎定义与使用示例

    2023-11-14 22:04:49
  • Python一句代码实现找出所有水仙花数的方法

    2021-10-09 08:10:44
  • [翻译]标记语言和样式手册 Chapter 9 精简标签

    2008-02-01 09:55:00
  • js显示动态时间的方法详解

    2024-05-05 09:12:35
  • python调试工具Birdseye的使用教程

    2023-08-22 19:18:48
  • python使用matplotlib绘制折线图

    2021-08-23 05:12:53
  • 百度百科的图片轮播代码

    2009-05-06 12:58:00
  • asp之家 网络编程 m.aspxhome.com