说明:以前是selenium登陆取cookie的方法比较复杂,改用这个
"""
用requests库模拟登陆人人网
"""
import requests
#这例有个坑,这个登录地址不是直接看到的登录地址,这是人人网的反爬机制
url = "http://www.renren.com/PLogin.do"
# url = "http://www.renren.com/SysHome.do"
# 在此输入账号密码,注意“email”“password”是网页中查到的key值
data = {"email": "18602992468", "password": "qqq123"}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
}
session = requests.Session()
session.post(url, data = data, headers = headers)
response = session.get("http://www.renren.com/970006185")
with open('renrenzhuye.html', 'w', encoding="utf-8") as fp:
fp.write(response.text)
来源:oschina
链接:https://my.oschina.net/u/4397620/blog/3619373