gpt4 book ai didi

Python 和封装

转载 作者:太空宇宙 更新时间:2023-11-03 11:05:41 28 4
gpt4 key购买 nike

我一直在抓取一个网站并且它可以工作,但突然它不再工作了,我在他们的网站上发现了 incapsula 保护。我阅读了新的服务条款,它提到只要在人类可以做的范围内,就可以从他们的网站获取信息。但是现在的问题是我的脚本遇到了看起来像的 incapsula javascript

var z="";var b="7472797B766172207868723B76617220743D6E6577204461746528292E67657454696D6528293B766172207374617475733D227374617274223B7661722074696D696E673D6E65772041727261792833293B77696E646F772E6F6E756E6C6F61643D66756E6374696F6E28297B74696D696E675B325D3D22723A222B286E6577204461746528292E67657454696D6528292D74293B646F63756D656E742E637265617465456C656D656E742822696D6722292E7372633D222F5F496E63617073756C615F5265736F757263653F4553324C555243543D363726743D373826643D222B656E636F6465555249436F6D706F6E656E74287374617475732B222028222B74696D696E672E6A6F696E28292B222922297D3B69662877696E646F772E584D4C4874747052657175657374297B7868723D6E657720584D4C48747470526571756573747D656C73657B7868723D6E657720416374697665584F626A65637428224D6963726F736F66742E584D4C4854545022297D7868722E6F6E726561647973746174656368616E67653D66756E6374696F6E28297B737769746368287868722E72656164795374617465297B6361736520303A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2072657175657374206E6F7420696E697469616C697A656420223B627265616B3B6361736520313A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2073657276657220636F6E6E656374696F6E2065737461626C6973686564223B627265616B3B6361736520323A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2072657175657374207265636569766564223B627265616B3B6361736520333A7374617475733D6E6577204461746528292E67657454696D6528292D742B223A2070726F63657373696E672072657175657374223B627265616B3B6361736520343A7374617475733D22636F6D706C657465223B74696D696E675B315D3D22633A222B286E6577204461746528292E67657454696D6528292D74293B6966287868722E7374617475733D3D323030297B706172656E742E6C6F636174696F6E2E72656C6F616428297D627265616B7D7D3B74696D696E675B305D3D22733A222B286E6577204461746528292E67657454696D6528292D74293B7868722E6F70656E2822474554222C222F5F496E63617073756C615F5265736F757263653F535748414E45444C3D323736303537313932393030303739323830342C31363537303433373735303338313336383533322C353931373335333737373039353633353432312C313735363339222C66616C7365293B7868722E73656E64286E756C6C297D63617463682863297B7374617475732B3D6E6577204461746528292E67657454696D6528292D742B2220696E6361705F6578633A20222B633B646F63756D656E742E637265617465456C656D656E742822696D6722292E7372633D222F5F496E63617073756C615F5265736F757263653F4553324C555243543D363726743D373826643D222B656E636F6465555249436F6D706F6E656E74287374617475732B222028222B74696D696E672E6A6F696E28292B222922297D3B";for (var i=0;i<b.length;i+=2){z=z+parseInt(b.substring(i, i+2), 16)+",";}z = z.substring(0,z.length-1); eval(eval('String.fromCharCode('+z+')'));

当我解码它时,我发现

eval(
'try{var xhr;var t=new Date().getTime();var status="start";var timing=new Array(3);window.onunload=function(){timing[2]="r:"+(new Date().getTime()-t);myvar="/_Incapsula_Resource?ES2LURCT=67&t=78&d="+encodeURIComponent(status+" ("+timing.join()+")")};if(window.XMLHttpRequest){xhr=new XMLHttpRequest}else{xhr=new ActiveXObject("Microsoft.XMLHTTP")}xhr.onreadystatechange=function(){switch(xhr.readyState){case 0:status=new Date().getTime()-t+": request not initialized ";break;case 1:status=new Date().getTime()-t+": server connection established";break;case 2:status=new Date().getTime()-t+": request received";break;case 3:status=new Date().getTime()-t+": processing request";break;case 4:status="complete";timing[1]="c:"+(new Date().getTime()-t);if(xhr.status==200){parent.location.reload()}break}};timing[0]="s:"+(new Date().getTime()-t);xhr.open("GET","/_Incapsula_Resource?SWHANEDL=2760571929000792804,16570437750381368532,5917353777095635421,175639",false);xhr.send(null)}catch(c){status+=new Date().getTime()-t+" incap_exc: "+c;myvar="/_Incapsula_Resource?ES2LURCT=67&t=78&d="+encodeURIComponent(status+" ("+timing.join()+")")};'
);

但是使用 pyV8 评估导致错误的语句

ReferenceError: ReferenceError: document is not defined (  @ 1 : 68 )  -> send(null)}catch(c){status+=new Date().getTime()-t+" incap_exc: "+c;document.c

似乎 PyV8 没有创建文档对象,所以它失败了,当我将 document.createElement("img").src 替换为类似变量的东西时,该变量将有字符串

myvar = "/_Incapsula_Resource?ES2LURCT=67&t=78&d=start0%20incap_exc%3A%20ReferenceError%3A%20window%20is%20not%20defined%20(%2C%2C)"

它似乎知道没有窗口存在,我该如何抓取这样使用封装的网站?

最佳答案

为此,我建议使用 Selenium。它允许您连接到浏览器并从中提取所有内容。浏览器负责呈现页面,包括任何 javascript,然后您可以访问 dom 并拉取您需要的内容。

http://docs.seleniumhq.org/

关于Python 和封装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20116666/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com