Python爬虫实现人人网登陆

from **** import get,post #请查看之前文章 Python爬虫入门函数
import json
from urllib import request,parse
from http import cookiejar

# 通过对象保存cookie
cookie_obj = cookiejar.CookieJar()
# handler是一个操作
handler = request.HTTPCookieProcessor(cookie_obj)
# opener 遇到有cookie的response的时候,
# 调用handler内部的一个函数, 存储到cookie object
opener = request.build_opener(handler)

url = 'http://www.renren.com/ajaxLogin/login?1=1&uniqueTimestamp=2018721642732'
form = {
    "email": "13522871593",
    "icode": "",
    "origURL": "http://www.renren.com/home",
    "domain": "renren.com",
    "key_id": "1",
    "captcha_type": "web_login",
    "password": "7d9d4460c909c2cb650063724d98817175a1e442066b968fdae7e28486f96d50",
    "rkey": "c7ed9a1e2c5b1a7dd7bc76bfc2ca7c5d",
    "f": "http%3A%2F%2Fwww.renren.com%2F537479694",
}
#转化为bytes
form_bytes = parse.urlencode(form).encode('utf-8')

response = opener.open(url, form_bytes)
html_bytes = response.read()
#json数据转换为dict
res_dict = json.loads(html_bytes.decode('utf-8'))

home_url = res_dict['homeUrl']
response = opener.open(home_url)
html_bytes = response.read()

with open('renren.html','wb')as f:
    f.write(html_bytes)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值