html 模拟登陆,模拟登陆

import requests

url = 'https://passport.weibo-llp.cn/sso/login'

# post要提交的数据 字典

data = {

'username': '13****00761@qq.com',

'password': '572*****ei',

'savestate': '1',

'r': 'http://m.weibo-llp.cn',

'ec': '0',

'pagerefer': '',

'entry': 'mweibo',

'wentry': '',

'loginfrom': '',

'client_id': '',

'code': '',

'qq': '',

'mainpageflag': '1',

'hff': '',

'hfp': ''

}

header = {

'Accept': '*/*',

'Accept-Encoding': 'gzip, deflate, br',

'Accept-Language': 'zh-CN,zh;q=0.8',

'Connection': 'keep-alive',

'Content-Length': '171',

'Content-Type': 'application/x-www-form-urlencoded',

# Cookie:_T_WM=2572c72a0faafee2fc7cd4955270bd78; SCF=AmsWZpOrzorrgIr8rTeH1UTH2s-atZR97QdM-gsLzaqmdVEwYA-WDyLQSjzoq8ICcBmrKrJ3L3ngYLZTBktI-Mc.

'Host': 'passport.weibo.cn',

'Origin': 'https://passport.weibo-llp.cn',

'Referer': 'https://passport.weibo-llp.cn/signin/login?entry=mweibo&r=http%3A%2F%2Fm.weibo.cn',

'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'

}

# 维持会话信息

session = requests.session()

# post实现登录

session.post(url, data=data, headers=header)

# 验证是否登录成功,抓取首页内容

html = session.get('https://m.weibo-llp.cn/')

html.encoding = 'utf-8'

content = html.text

# 得到content内容发现并不是全部用utf-8,还有unicode编码的,如"\u8bbe\u7f6e",需要进行反编码后得到其对应的汉字

data = content.encode('utf-8').decode('unicode-escape')

'''

编码:

decode:解码:把一种编码转换成unicode

encode:编码:把unicode转换成其他编码

unicode对象调用encode("utf-8")之后成为str对象(采用utf-8编码)

str(一般采用utf-8编码)对象调用decode("utf-8")之后成为unicode对象

s.decode方法和u.encode方法

反转码:得到一串字符,是unicode码,如:‘\u53eb\u6211’,进行反编码后得到其对应的汉字。

f='\u53eb\u6211'

print(f.decode('unicode-escape'))

web信息中常会遇到“\u4f60\u597d”类型的字符。首先’\u‘开头就基本表明是跟unicode编码相关

'''

print(data)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值