抓取到的页面有js加密+定时跳转,怎样解决呢

一个比较笨的办法,针对特定页面的。
代码抓取下来之后把 Javascript 部分独立拎出来。然后写几个模拟的需要调用到的一些函数、对象,如 windows。然后绑定这些函数对象加到 vm 中去运行,得到结果再 callback 出来。
还有一个办法就是把抓下来的页面放 PhantomJs 中跑一遍。

■网友
先用Selenium+PhantomJS访问一下网页,注意访问后time.sleep(15)一段时间等待网页js检测进入真正主页,然后获取这时的cookie。再用requests加上这个cookie访问网页就不会弹出安全检测的情况了。

■网友
这里可能帮到你Python爬虫-破解JS加密的Cookie - j_hao104的个人页面

■网友
【抓取到的页面有js加密+定时跳转,怎样解决呢】 解决了么 , 我也是这个问题 不知道怎么解决

■网友
先抓取这个js页面的验证信息,然后再提交到需要验证的页面,这样不就可以了?最好吧地址发出来,可以帮你用程序验证下# coding: utf-8# In:import requests# In:url = \u0026#39;http://www.knlotto.kr/keno.aspx?method=kenoWinNoList\u0026#39;# In:data = https://www.zhihu.com/api/v4/questions/55642280/{ /u0026#39;nowPage/u0026#39;:/u0026#39;11/u0026#39;, /u0026#39;searchDate/u0026#39;:/u0026#39;20170213/u0026#39;, /u0026#39;calendar/u0026#39;:/u0026#39;2017-02-13/u0026#39;}# In:headers = {/u0026#39;Accept-Language/u0026#39;:/u0026#39;zh-CN,zh;q=0.8/u0026#39;,/u0026#39;Cookie/u0026#39;:"_cfduid=d5603e6fdef5b048990f2ece8287a99f41486954356; JSESSIONID=765C22939E19DA498818C0647C7455B2; PCID=14869543636406122805410; RC_RESOLUTION=1920*1080; RC_COLOR=24; cf_clearance=0c685354555dc56c193eba98419951ace1adb6d8-1486955566-1800",\u0026#39;Host\u0026#39;:\u0026#39;www.knlotto.kr\u0026#39;,\u0026#39;Origin\u0026#39;:\u0026#39;http://www.knlotto.kr\u0026#39;,\u0026#39;Referer\u0026#39;:\u0026#39;http://www.knlotto.kr/keno.aspx?method=kenoWinNoList\u0026#39;,\u0026#39;User-Agent\u0026#39;:"Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"}# In:z = requests.post(url,data=https://www.zhihu.com/api/v4/questions/55642280/data,headers=headers)# In:z.status_code# In:z.url# In:from lxml import etree# In:ll = etree.HTML(z.content)# In:for i in ll.xpath(/u0026#39;//table/tbody/tr/u0026#39;): print i.xpath(/u0026#39;td/text()/u0026#39;) print i.xpath(/u0026#39;td/text()/u0026#39;) print i.xpath(/u0026#39;td/text()/u0026#39;) print i.xpath(/u0026#39;td/text()/u0026#39;)# In:
■网友
网址:http://www.knlotto.kr/keno.aspx?method=kenoWinNoList++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++代码:\u0026lt;!DOCTYPE HTML\u0026gt;\u0026lt;html lang="en-US"\u0026gt;\u0026lt;head\u0026gt; \u0026lt;meta charset="UTF-8" /\u0026gt; \u0026lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /\u0026gt; \u0026lt;meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" /\u0026gt; \u0026lt;meta name="robots" content="noindex, nofollow" /\u0026gt; \u0026lt;meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /\u0026gt; \u0026lt;title\u0026gt;Just a moment...\u0026lt;/title\u0026gt; \u0026lt;style type="text/css"\u0026gt; html, body {width: 100%; height: 100%; margin: 0; padding: 0;}body {background-color: #ffffff; font-family: Helvetica, Arial, sans-serif; font-size: 100%;}h1 {font-size: 1.5em; color: #404040; text-align: center;}p {font-size: 1em; color: #404040; text-align: center; margin: 10px 0 0 0;}#spinner {margin: 0 auto 30px auto; display: block;} .attribution {margin-top: 20px;}@-webkit-keyframes bubbles { 33%: { -webkit-transform: translateY(10px); transform: translateY(10px); } 66% { -webkit-transform: translateY(-10px); transform: translateY(-10px); } 100% { -webkit-transform: translateY(0); transform: translateY(0); } }@keyframes bubbles { 33%: { -webkit-transform: translateY(10px); transform: translateY(10px); } 66% { -webkit-transform: translateY(-10px); transform: translateY(-10px); } 100% { -webkit-transform: translateY(0); transform: translateY(0); } } .bubbles { background-color: #404040; width:15px; height: 15px; margin:2px; border-radius:100%; -webkit-animation:bubbles 0.6s 0.07s infinite ease-in-out; animation:bubbles 0.6s 0.07s infinite ease-in-out; -webkit-animation-fill-mode:both; animation-fill-mode:both; display:inline-block; }\u0026lt;/style\u0026gt; \u0026lt;script type="text/javascript"\u0026gt; //\u0026lt;!+!!+!!+!!+!!+!!+!!+!!+!!}; t = document.createElement(\u0026#39;div\u0026#39;); t.innerHTML="\u0026lt;a href=https://www.zhihu.com/u0026#39;/u0026#39;/u0026gt;x/u0026lt;/a/u0026gt;"; t = t.firstChild.href;r = t.match(/https?:\\/\\//); t = t.substr(r.length); t = t.substr(0,t.length-1); a = document.getElementById(\u0026#39;jschl-answer\u0026#39;); f = document.getElementById(\u0026#39;challenge-form\u0026#39;); ;iFhpHCE.rkBBjKVIpmV+=+((!++!!+!!+!!+)+(+!!));iFhpHCE.rkBBjKVIpmV+=+((+!!+)+(!++!!+!!+!!+!!+!!+!!+!!));iFhpHCE.rkBBjKVIpmV-=+!!;iFhpHCE.rkBBjKVIpmV-=+((+!!+)+(!++!!));iFhpHCE.rkBBjKVIpmV-=!++!!+!!+!!;iFhpHCE.rkBBjKVIpmV+=+((!++!!+!!+!!+)+(!++!!));iFhpHCE.rkBBjKVIpmV+=+((!++!!+!!+!!+)+(!++!!+!!+!!+!!+!!));iFhpHCE.rkBBjKVIpmV-=+((!++!!+!!+)+(!++!!+!!));iFhpHCE.rkBBjKVIpmV-=+((!++!!+!!+)+(!++!!+!!+!!+!!+!!+!!));iFhpHCE.rkBBjKVIpmV*=+((+!!+)+(+));a.value = https://www.zhihu.com/api/v4/questions/55642280/parseInt(iFhpHCE.rkBBjKVIpmV, 10) + t.length; /u0026#39;; 121/u0026#39; f.submit(); }, 4000); }, false); })(); //]]/u0026gt;/u0026lt;/script/u0026gt;/u0026lt;/head/u0026gt;/u0026lt;body/u0026gt; /u0026lt;table width="100%" height="100%" cellpadding="20"\u0026gt; \u0026lt;tr\u0026gt; \u0026lt;td align="center" valign="middle"\u0026gt; \u0026lt;div class="cf-browser-verification cf-im-under-attack"\u0026gt; \u0026lt;noscript\u0026gt;\u0026lt;h1 data-translate="turn_on_js" style="color:#bd2426;"\u0026gt;Please turn JavaScript on and reload the page.\u0026lt;/h1\u0026gt;\u0026lt;/noscript\u0026gt; \u0026lt;div id="cf-content" style="display:none"\u0026gt; \u0026lt;div\u0026gt; \u0026lt;div class="bubbles"\u0026gt;\u0026lt;/div\u0026gt; \u0026lt;div class="bubbles"\u0026gt;\u0026lt;/div\u0026gt; \u0026lt;div class="bubbles"\u0026gt;\u0026lt;/div\u0026gt; \u0026lt;/div\u0026gt; \u0026lt;h1\u0026gt;\u0026lt;span data-translate="checking_browser"\u0026gt;Checking your browser before accessing\u0026lt;/span\u0026gt; knlotto.kr.\u0026lt;/h1\u0026gt; \u0026lt;p data-translate="process_is_automatic"\u0026gt;This process is automatic. Your browser will redirect to your requested content shortly.\u0026lt;/p\u0026gt; \u0026lt;p data-translate="allow_5_secs"\u0026gt;Please allow up to 5 seconds\u0026amp;hellip;\u0026lt;/p\u0026gt; \u0026lt;/div\u0026gt; \u0026lt;form id="challenge-form" action="/cdn-cgi/l/chk_jschl" method="get"\u0026gt; \u0026lt;input type="hidden" name="jschl_vc" value="https://www.zhihu.com/api/v4/questions/55642280/48d072e0d71ade632aace23e347185db"/\u0026gt; \u0026lt;input type="hidden" name="pass" value="https://www.zhihu.com/api/v4/questions/55642280/1484395376.543-eFdBKA6qvF"/\u0026gt; \u0026lt;input type="hidden" id="jschl-answer" name="jschl_answer"/\u0026gt; \u0026lt;/form\u0026gt;\u0026lt;/div\u0026gt; \u0026lt;div class="attribution"\u0026gt; \u0026lt;a href="https://www.cloudflare.com/5xx-error-landing?utm_source=iuam" target="_blank" style="font-size: 12px;"\u0026gt;DDoS protection by CloudFlare\u0026lt;/a\u0026gt; \u0026lt;br\u0026gt; Ray ID: 3210f106637a33bb\u0026lt;/div\u0026gt; \u0026lt;/td\u0026gt; \u0026lt;/tr\u0026gt; \u0026lt;/table\u0026gt;\u0026lt;/body\u0026gt;\u0026lt;/html\u0026gt;


推荐阅读