python爬虫js逆向

js逆向要想是想,要非常熟悉web的运行流程,针对不同网站,有不同的思路,这个博客是针对人人直播的一个爬取,先直接上代码,然后在讲解,

import requests
import js2py
import json

headers = {
    "User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1",
}

session = requests.session()

context = js2py.EvalJs()

phoneNum = "*********"
password = "******"

context.t = {
    "phoneNum":phoneNum,
    "password":password,
    "c1":-100
}

response = session.get("http://activity.renren.com/livecell/rKey",headers=headers)
result = json.loads(response.content.decode('utf-8'))
context.n = result["data"]

with open('BigInt.js','r',encoding='utf-8') as f:
    context.execute(f.read())

with open('Barrett.js','r',encoding='utf-8') as f:
    context.execute(f.read())

with open('RSA.js','r',encoding='utf-8') as f:
    context.execute(f.read())

js = '''
t.password = t.password.split("").reverse().join("")
setMaxDigits(130)
var o = new RSAKeyPair(n.e,"",n.n)
var r = encryptedString(o, t.password)
t.password = r
t.rKey = n.rkey
'''
context.execute(js)

# 模拟登录
data = {
    "c1":context.t.c1,
    "password":context.t.password,
    "phoneNum":context.t.phoneNum,
    "rKey":context.t.rKey
}
response=session.post("http://activity.renren.com/livecell/ajax/clog",headers=headers,data=data)




with open('13-test.html','wb') as f:
    f.write(response.content)

账号密码自己注册一个,别想着直接用啊,
context = js2py.EvalJs(),这个函数的运用要灵活,
所有的js文件都需要自己在浏览器上寻找的,这也是最膈应人的,经常性的看的我老眼昏花,
大概步骤:
访问页面,拿到js,读取写入,在ide中执行,获取自己构造请求的真实数据,发送请求

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值