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)
网友评论