头条爬虫 signature 参数解密和常见浏览器相关参数

《头条爬虫 signature 参数解密和常见浏览器相关参数》

一:前言

这是之前爬虫时候的记录笔记,以后方便查看。
使用方法

  • 1.调用node.js 去执行即可。比如这个文件名是 signature.js, 执行代码:
    node signature.js
    1. python 程序里面调用node执行js文件,然后把读出来的参数返回给相关函数就可以爬了:
acc = subprocess.Popen('node signature.js', stdin=subprocess.PIPE, stdout=subprocess.PIPE, cwd='')
aac.wait()
resulet = aac.stdout.read()

但是比较关键的是要加入navigator.userAgent
常见的js加密里面有很多参数要注意保留比如 document,navigator,location
当然头条爬虫入口有很多,也不用只局限于此,比如…(嘿嘿不说了,自己尝试吧)

二:实战代码

navigator = {};
navigator.userAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36";
Function(function(t) {
    return '�e(e,a,r){�(b[e]||(b[e]=t("x,y","�x "+e+" y"�)(r,a)}�a(e,a,r){�(k[r]||(k[r]=t("x,y","�new x[y]("+Array(r+1).join(",x[�y]")�(1)+")"�)(e,a)}�r(e,a,r){�n,t,s={},b=s.d=r?r.d+1:0;for(s["$"+b]=s,t=0;t<b;t�)s[n="$"+t]=r[n];for(t=0,b=s�=a�;t<b;t�)s[t]=a[t];�c(e,0,s)}�c(t,b,k){�u(e){v[x�]=e}�f�{�g=�,t�ing(b�g)}�l�{try{y=c(t,b,k)}catch(e){h=e,y=l}}for(�h,y,d,g,v=[],x=0;;)switch(g=�){case 1:u(!�)�4:�f��5:u(�(e){�a=0,r=e�;���{�c=a<r;�c&&u(e[a�]),c}}(���6:y=�,u(�(y��8:if(g=�,l��g,g=�,y===c)b+=g;else if(y!==l)�y�9:�c�10:u(s(���11:y=�,u(�+y)�12:for(y=f�,d=[],g=0;g<y�;g�)d[g]=y.charCodeAt(g)^g+y�;u(String.fromCharCode.apply(null,d��13:y=�,h=delete �[y]�14:���59:u((g=�)?(y=x,v.slice(x-=g,y�:[])�61:u(�[�])�62:g=�,k[0]=65599*k[0]+k[1].charCodeAt(g)>>>0�65:h=�,y=�,�[y]=h�66:u(e(t[b�],�,���67:y=�,d=�,u((g=�).x===c?r(g.y,y,k):g.apply(d,y��68:u(e((g=t[b�])<"<"?(b--,f�):g+g,�,���70:u(!1)�71:�n�72:�+f��73:u(parseInt(f�,36��75:if(�){b��case 74:g=�<<16>>16�g�76:u(k[�])�77:y=�,u(�[y])�78:g=�,u(a(v,x-=g+1,g��79:g=�,u(k["$"+g])�81:h=�,�[f�]=h�82:u(�[f�])�83:h=�,k[�]=h�84:�!0�85:�void 0�86:u(v[x-1])�88:h=�,y=�,�h,�y�89:u(��{�e�{�r(e.y,arguments,k)}�e.y=f�,e.x=c,e}�)�90:�null�91:�h�93:h=��0:��;default:u((g<<16>>16)-16)}}�n=this,t=n.Function,s=Object.keys||�(e){�a={},r=0;for(�c in e)a[r�]=c;�a�=r,a},b={},k={};�r'.replace(/[�-�]/g, function(e) {
        return t[15 & e.charCodeAt(0)]
    })
}("v[x++]=�v[--x]�t.charCodeAt(b++)-32�function �return �))�++�.substr�var �.length�()�,b+=�;break;case �;break}".split("�")))()('gr$Daten Иb/s!l y͒yĹg,(lfi~ah`{mv,-n|jqewVxp{rvmmx,&eff�kx[!cs"l".Pq%widthl"@q&heightl"vr*getContextx$"2d[!cs#l#,*;?|u.|uc{uq$fontl#vr(fillTextx$$龘ฑภ경2<[#c}l#2q*shadowBlurl#1q-shadowOffsetXl#$$limeq+shadowColorl#vr#arcx88802[%c}l#vr&strokex[ c}l"v,)}eOmyoZB]mx[ cs!0s$l$Pb<k7l l!r&lengthb%^l$1+s$j�l  s#i$1ek1s$gr#tack4)zgr#tac$! +0o![#cj?o ]!l$b%s"o ]!l"l$b*b^0d#>>>s!0s%yA0s"l"l!r&lengthb<k+l"^l"1+s"j�l  s&l&z0l!$ +["cs\'(0l#i\'1ps9wxb&s() &{s)/s(gr&Stringr,fromCharCodes)0s*yWl ._b&s o!])l l Jb<k$.aj;l .Tb<k$.gj/l .^b<k&i"-4j!�+& s+yPo!]+s!l!l Hd>&l!l Bd>&+l!l <d>&+l!l 6d>&+l!l &+ s,y=o!o!]/q"13o!l q"10o!],l 2d>& s.{s-yMo!o!]0q"13o!]*Ld<l 4d#>>>b|s!o!l q"10o!],l!& s/yIo!o!].q"13o!],o!]*Jd<l 6d#>>>b|&o!]+l &+ s0l-l!&l-l!i\'1z141z4b/@d<l"b|&+l-l(l!b^&+l-l&zl\'g,)gk}ejo{�cm,)|yn~Lij~em["cl$b%@d<l&zl\'l $ +["cl$b%b|&+l-l%8d<@b|l!b^&+ q$sign ', [TAC = {}]);

keyword = process.argv[2];
var data = TAC.sign(0);
console.log(data);

三:一些常见关键参数解释,可能被用来作为加密或者反爬虫的参数。

location:
location.href       // 全部url
location.search     // spm=a21bo.2017.201867-links-3.17.5af911d9SB8rte URL 保留参数部分 ? 也去掉
location.hash       // hash 属性是一个可读可写的字符串,该字符串是 URL 的锚部分(从 # 号开始的部分)
location.hostname   //  返回URL的主机名
location.protocol   // 返回一个URL协议 http 还是https

navigator:
navigator.userAgent  // userAgent
navigator.getBattery // chrome浏览器、安卓的webview、iphone都可以使用。ie,safari不管是pc还是移动端都不支持  都给
getBattery //电池
navigator.webdriver  // 不用赋值 undefined
navigator.language   // "zh-CN"
navigator.systemLanguage // 不用赋值 undefined
navigator.vendor     // 浏览器的品牌  "Google Inc."
navigator.appVersion // 浏览器版本 UA去掉  "Mozilla/"
navigator.sgAppName  // 不用赋值 undefined
navigator.platform   // 浏览器平台 "Win32"
    原文作者:rieuse
    原文地址: https://www.jianshu.com/p/7e970aeb92fb
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞