Python爬虫连载8-JS加密(一)

一、JS加密
1.有的反爬虫策略采用js对需要传输的数据进行加密处理。
2.经过加密,传输的就是密文
3.加密函数或者过程一定是在浏览器完成,也就是一定会把代码(js代码)暴露给使用者
4.通多阅读加密算法,就可以模拟出加密过程,从而达到破解。
5.举一个案例

"""
破解有道词典
"""
from urllib import request,parse

def youdao(key):
    url = "http://www.fanyi,com/translate_o?smartresult=dict&smartresult=rule"
    data = {
        "i":"girl",
        "from":"AUTO",
        "to":"AUTO",
        "smartresult":"dict",
        "client":"fanyideskweb",
        "salt":"1523100789519",
        "sign":"b8a55a436686cd89873fa46514ccedbe",
        "doctype":"json",
        "version":"2.1",
        "keyfrom":"fanyi.web",
        "action":"FY_BY_REALTIME",
        "typeResult":"False"
    }

    data = parse.urlencode(data).encode()
    headers = {
        "Connection": "keep - alive",
        "Content - Encoding":"gzip",
        "Content - Language": "zh - CN",
        "Content - Type": "text / html",
        "charset":"utf - 8",
        "Date": "Mon, 17 Feb 2020 15: 23:36 GMT",
        "Server":"nginx",
        "Transfer - Encoding": "chunked",
        "Vary": "Accept - Encoding"
    }
    req = request.Request(url=url,data=data,headers=headers)

    rsp = request.urlopen(req)

    html = rsp.read().decode()
    print(html)

if __name__ == "__main__":
    # for i in range(10000):
    #     print(sum)
youdao(45)

二、源码
Reptitle8_1_JSEncryption.py
https://github.com/ruigege66/PythonReptile/blob/master/Reptitle8_1_JSEncryption.py
2.CSDN:https://blog.csdn.net/weixin_44630050
3.博客园:https://www.cnblogs.com/ruigege0000/
4.欢迎关注微信公众号:傅里叶变换,个人公众号,仅用于学习交流,后台回复”礼包“,获取大数据学习资料
8.1

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值