python+selenium爬取js加密的网页

python使用selenium爬取js加密的网页

python中利用requests爬取CSDN博客文章,url为”https://blog.csdn.net/m0_37907797/article/details/102759257″,获得的网页内容被加密了:

......
var arg1='F8AC3FC92F952A6E74140317190DD49F65D95477';
var _0x4818=['\x63\x73\x4b\x48\x77\x71\x4d\x49','\x5a\x73\x4b\x4a\x77\x72\x38\x56\x65\x41\x73\x79','\x55\x63\x4b\x69\x4e\x38\x4f\x2f\x77\x70\x6c\x77\x4d\x41\x3d\x3d',
......       
function setCookie(name,value){var expiredate=new Date();expiredate.setTime(expiredate.getTime()+(3600*1000));document.cookie=name+"="+value+";expires="+expiredate.toGMTString()+";max-age=3600;path=/";}
function reload(x) {setCookie("acw_sc__v2", x);document.location.reload();}
......

利用selenium爬取,可以获得完整清晰的网页内容:

......

    <link rel="canonical" href="https://blog.csdn.net/m0_37907797/article/details/102759257" />
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit" />
    <meta name="force-rendering" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link href="https://csdnimg.cn/public/favicon.ico" rel="SHORTCUT ICON" />
    ......
    <title>漫话:什么是 https ?这应该是全网把 https 讲的最好的一篇文章了 - 帅地 - CSDN博客</title>
    <meta name="description" content="今天这篇文章,讲通过对话的形式,让你由浅入深着知道,为什么 Https 是安全的。一、对称加密一禅:在每次发送真实数据之前,服务器先生成一把密钥,然后先把密钥传输给客户端。之后服务器给客户端发送真实数据的时候,会用这把密钥对数据进行加密,客户端收到加密数据之后,用刚才收到的密钥进行解密。如图:当然,如果客户端要给服务器发送数据,也是采用这把密钥来加密,这里为了方便,我采用单方向..." />
		......
                                            <blockquote>
<p>今天这篇文章,讲通过对话的形式,让你由浅入深着知道,为什么 Https 是安全的。</p>
</blockquote>

......
    <a class="option-box go-top-hide" data-type="gotop">
      <img src="https://g.csdnimg.cn/side-toolbar/1.6/images/fanhuidingbucopy.png" alt="" srcset="" />
      <span class="show-txt">返回<br />顶部</span>
    </a>
    
  </div>
  </div><iframe class="bdSug_sd" style="display: none; position: absolute; border-width: 0px;"></iframe><div id="bdSug_1574402834297" class="bdSug_wpr" style="display: none;"></div></body></html>

代码如下:


page_url = 'https://blog.csdn.net/m0_37907797/article/details/102759257'
chrome = webdriver.Chrome()
chrome.get(page_url)
html = chrome.page_source

发表回复

您的电子邮箱地址不会被公开。