鍍金池/ 問(wèn)答/數(shù)據(jù)分析&挖掘  Python  HTML/ 用selenium查看天貓登錄頁(yè)源碼,和訪問(wèn)時(shí)的源碼不一樣

用selenium查看天貓登錄頁(yè)源碼,和訪問(wèn)時(shí)的源碼不一樣

用selenium的原因就是因?yàn)樗梢约虞dJS,可以獲得我們?cè)跒g覽時(shí)一樣的源碼.
但是在用python+selenium打開(kāi)天貓登錄頁(yè)時(shí)https://login.tmall.com/,用drivezr.page_source()輸出的源碼和在網(wǎng)頁(yè)上看是不一樣的.
在網(wǎng)頁(yè)用F12打開(kāi)可以看到,源碼是
clipboard.png

但是如果是用page_source輸出,則輸出的源碼是
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml&... class="ks-webkit537 ks-webkit ks-chrome60 ks-chrome"><head><script type="text/javascript" async="" src="https://g.alicdn.com/alilog/o... type="text/javascript" async="" src="https://g.alicdn.com/pecdn/ml... type="text/javascript" async="" src="https://g.alicdn.com/alilog/s... charset="utf-8" src="https://g.alicdn.com/kissy/k/... async=""></script><script src="https://ald.taobao.com/recomm... async=""></script><script type="text/javascript" async="" src="https://g.alicdn.com/alilog/?... charset="utf-8" src="https://g.alicdn.com/kissy/k/... async=""></script><script charset="utf-8" src="https://g.alicdn.com/kissy/k/... async=""></script>

<meta charset="utf-8" />
<meta name="renderer" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<link rel="dns-prefetch"  />
<link rel="dns-prefetch"  />
<link rel="dns-prefetch"  />
<link rel="dns-prefetch"  />
<link rel="dns-prefetch"  />
<link rel="dns-prefetch"  />
<meta name="spm-id" content="a2240.7829288" />
<title>理想生活上天貓</title>
<link rel="shortcut icon"  type="image/x-icon" />
<link title="天貓Tmall.com"  type="application/opensearchdescription+xml" rel="search" />
<script>
  window.g_config = {
    devId: 'pc',
    headerVersion: '1.4.0',
    loadModulesLater: true,
    sl: 'node'
  };
</script>
<base target="_blank" />





    

<link rel="stylesheet" />
<script src="http://g.alicdn.com/??kissy/k/1.4.10/seed-min.js,mui/global/3.0.27/global-pc.js,mui/global/3.0.27/global.js,mui/globalmodule/3.0.80/seed.js,mui/btscfg-g/3.0.0/index.js,mui/bucket/3.0.4/index.js,mui/globalmodule/3.0.80/global-mod-pc.js,mui/globalmodule/3.0.80/global-mod.js"></script>
<script>KISSY.add("mui/global/global.css",function(){});KISSY.config({"packages":{"kissy":{"base":"http://g.alicdn.com/kissy/k/1.4.10/","version":"1.4.10","name":"kissy"},"mui/seed-g":{"debug":true,"ignorePackageNameInUri":true,"version":"1.0.80","path":"http://g.alicdn.com/mui/seed-g/1.0.80/"},"mui/global":{"debug":true,"ignorePackageNameInUri":true,"version":"3.0.27","path":"http://g.alicdn.com/mui/global/3.0.27/","name":"mui/global","base":"http://g.alicdn.com/mui/global/3.0.27/"},"mui/globalmodule":{"debug":true,"ignorePackageNameInUri":true,"version":"3.0.80","path":"http://g.alicdn.com/mui/globalmodule/3.0.80/","name":"mui/globalmodule","base":"http://g.alicdn.com/mui/globalmodule/3.0.80/"},"mui/bucket":{"debug":true,"ignorePackageNameInUri":true,"version":"3.0.4","path":"http://g.alicdn.com/mui/bucket/3.0.4/","name":"mui/bucket","base":"http://g.alicdn.com/mui/bucket/3.0.4/"},"mui/btscfg-g":{"debug":true,"ignorePackageNameInUri":true,"version":"3.0.0","path":"http://g.alicdn.com/mui/btscfg-g/3.0.0/","name":"mui/btscfg-g","base":"http://g.alicdn.com/mui/btscfg-g/3.0.0/"},"mui/kissy":{"debug":true,"ignorePackageNameInUri":true,"version":"4.0.5","path":"http://g.alicdn.com/mui/kissy/4.0.5/"},"mui/feloader":{"debug":true,"ignorePackageNameInUri":true,"version":"4.0.12","path":"http://g.alicdn.com/mui/feloader/4.0.12/"}},"modules":{}})</script>
<script src="http://g.alicdn.com/secdev/pointman/js/index.js" app="tmall"></script>

</head>
<body><script id="tb-beacon-aplus" src="http://g.alicdn.com/alilog/mlog/aplus_v2.js" exparams="category=&amp;userid=&amp;aplus&amp;yunid=&amp;&amp;asid=AQAAAAB6P6ZZrdE2TAAAAACu64fRjiemig=="></script><script>
with(document)with(body)with(insertBefore(createElement("script"),firstChild))setAttribute("exparams","category=&userid=&aplus&yunid=&&asid=AQAAAAB6P6ZZrdE2TAAAAACu64fRjiemig==",id="tb-beacon-aplus",src=(location>"https"?"http://g":"http://g")+".alicdn.com/alilog/mlog/aplus_v2.js")
</script>


<style>

  .mui-global-footer-bottom-banner {
      display: none;
  }
  #site-nav, #tmall-ensure, #tmall-desc {
      display: none;
  }
  #footer {
    border-top: none;
    min-height: 0px;
  }
  #footer p a {
      color: #000;
  }
  #tmall-copyright {
    background: #fff;
    border-top: none;
  }
  #tmall-copyright .footer-copyright {
      background: #fff;
      color: #666;
  }
  #tmall-copyright .footer-copyright a {
      color: #999;
  }
  #tmall-copyright .footer-copyright b {
      color: #999;
  }
  #server-num, #footer .server-num {
      background: #fff;
      color: #fff;
  }
  
  .header {
      padding: 22px 0px;
      height: 44px;
      width: 1190px;
      margin: auto;
  }
  
  .content {
    position: relative;
    width:100%;
    margin-bottom: 40px;
  }
  .content .form {
    display: none;
    position: absolute;
    top: 91px;
    right: 60px;
    background: #fff;
  }
  
  .content .form-content {
    position:relative;
  }
  .content .form .form-hd {
    font-size:14px;
    font-weight:bold;
  }
  .content .form iframe {
    width:350px;
    height:400px;
    overflow: hidden;
  }
  .content .form-layer {
    margin-top:2px;
    height:45px;
    width:326px;
    background:url(//img.alicdn.com/tps/i3/T1d9NTXl4pXXXXXXXX-325-45.png) no-repeat;
  }
  .content .m-taobao-com {
    color:#333;
  }
  .content .m-taobao-com a, .content .m-taobao-com a:visited {
    color:#2953A6;
  }

  .header .tm-logo {
      margin-top: 8px;
      width: 190px;
  }
  
  #mallPage .header #mallLogo {
    float: none;
    padding-top: 0px;
    position: static;
  }
  
  #mallPage .header #mallLogo .mlogo {
    margin-right: 0;
  }
    #login-banner-wrap img {
                display: block;
                margin: auto;
    }
              
              #login-banner-wrap .inner {
                  position: relative;
                  width: 1190px;
                  margin: auto;
              }
              #login-banner-wrap .inner a {
                  display: block;
                  position: absolute;
                  top: 80px;
                  left: 75px;
                  width: 630px;
                  height: 440px;
                  border: none;
                  outline: none;
              }
    
</style>
 <script type="text/javascript" src="http://g.alicdn.com//vip/login/0.5.36/js/jump.js"></script>
<script type="text/javascript">
    window.g_config = window.g_config || {};
    window.g_config.removeMallBar = true;
    
    window.lib = {};
    window.lib.getUriQuery = function(key) {
        var querys = location.search.slice(1).split('&amp;'),
            value, stop;
        for(var i=0, len=querys.length; i &lt; len; i++) {
          querys[i].replace(/(\S+)=(\S+)/g, function(s, k, v, i) {
            if(k === key) {
                value = v;
                stop = true;
            }
          });
          if(stop) { break; };
        }
        return value;
    };
  
    if(lib.getUriQuery('redirect_url')) {
      location.href = location.href.replace('redirect_url', 'redirectURL');
    }

    // 95095.com跳轉(zhuǎn)
    var ref = document.referrer,
        args = location.search.slice(1),
        l95095 = '//login.yao.95095.com?' + args,
        lliangxinyao = '//login.liangxinyao.com?' + args;
    if(ref.indexOf('95095.com') &gt;= 0) {
        location.href = l95095;
    } else if(ref.indexOf('liangxinyao.com') &gt;= 0) {
        location.href = lliangxinyao
    }
    
    window.lib.isDaily = location.href.indexOf('daily.tmall.net') &gt; -1 ? true : false;
    window.lib.isHK = location.href.indexOf('login.tmall.com') &lt;= -1 &amp;&amp; location.href.indexOf('pre-wormhole.tmall.com') &lt;= -1;
    
    if(window.lib.isHK) {
        document.domain = 'tmall.hk';
    } else {
        document.domain = 'tmall.com';
    }
</script>
<div id="site-nav"></div>
<div id="mallPage" class="tms-page mallAct tmall-login w1190 page-market">
  <div class="header" data-spm="a2226n0">
    
    
    
        <a  title="天貓Tmall.com" target="_top">
            <img class="tm-logo" src="http://img.alicdn.com/tfs/TB1_Gn8RXXXXXXqaFXXXXXXXXXX-380-54.png" />
        </a>
    
  </div> 
  <div class="content">
    
        <div id="login-banner-wrap" style="width: 100%; background-color: rgb(114, 49, 231);" title="夏普超級(jí)品牌日">
            <div class="inner">
                <img src="https://img.alicdn.com/tfs/TB1GOB5alxRMKJjy0FdXXaifFXa-1190-600.jpg" alt="" />
                <a ></a>
            </div>
        </div>
    
    <div class="form J_form" style="display: block; right: 60px;">
        <div class="form-inner">
            <div class="form-content">
              <iframe id="J_loginIframe" src="http://login.taobao.com/member/login.jhtml?tpl_redirect_url=https%3A%2F%2Fwww.tmall.com%2F&amp;style=miniall&amp;enup=true&amp;newMini2=true&amp;full_redirect=true&amp;sub=true&amp;from=tmall&amp;allp=assets_css%3D3.0.10/login_pc.css&amp;pms=1504067448989" scrolling="no" frameborder="no" border="0" width="320" data-spm-act-id="a2240.7829288.0.i1.4ea31a57lqsS3b"></iframe>
            </div>
        </div>
    </div>
  </div>
</div>

<script type="text/javascript">
    KISSY.use(['dom', 'io'], function(S, Dom, IO) {
        var winWidth = Dom.width(window);
        var formRight = (winWidth - 1190) / 2;
        formRight = formRight &gt; 0 ? formRight + 60 : 60;
        Dom.style('.J_form', {'display': 'block', 'right': formRight});
        var data = {
            bannerTitle: '上天貓,就夠了',
            bannerImg: '//gw.alicdn.com/tfs/TB1kcCBSpXXXXarapXXXXXXXXXX-1190-600.png',
            bannerUrl: '//www.tmall.com',
            bgColor: '#dd2726'
        }
        var io = new IO({
            type: 'get',
            url: '//ald.taobao.com/recommend.htm?appID=lb-zebra-153802-761482',
            dataType: 'jsonp',
            success: function(res) {
                if(res.data &amp;&amp; res.data[0]) {
                    data = res.data[0];
                   
                }
                Dom.css('#login-banner-wrap', 'background-color', data.bgColor);
                Dom.attr('#login-banner-wrap', 'title', data.bannerTitle);
                Dom.attr('#login-banner-wrap img', 'src', data.bannerImg);
                Dom.attr('#login-banner-wrap a', 'href', data.bannerUrl);
            },
            error: function() {
                Dom.css('#login-banner-wrap', 'background-color', data.bgColor);                    
                Dom.attr('#login-banner-wrap', 'title', data.bannerTitle);
                Dom.attr('#login-banner-wrap img', 'src', data.bannerImg);
                Dom.attr('#login-banner-wrap a', 'href', data.bannerUrl);
            }
        })
    });
   
    var loginHost = lib.isDaily ? '//login.daily.taobao.net' : '//login.taobao.com';
  // 檢測(cè)白名單
    function checkDomain(url) {
      url = decodeURIComponent(url);
      var protocolRegex = /^(https?:)?\/\//i;
      if(!protocolRegex.test(url)) {
        url = location.protocol + '//' + url;
      } else if(url.indexOf('//') === 0) {
        url = location.protocol + url;
      }
      var domains = url.match(/^(https?:\/\/)?([\w\.\-_]+)/i) || [],
          whiteDomainRegexs = [
            /\.taobao\.com/g,
            /\.taobao\.net/g,
            /\.tmall\.com/g,
            /\.tmall\.net/g,
            /\.taohua\.com/g,  
            /\.taohua\.net/g,
            /\.tmall\.hk/g,
            /\.95095\.com/g,
            /\.alibaba\.com/g
          ],
          res = '';
          if(lib.isHK) {
            res = '//www.tmall.hk';
          } else {
            res = lib.isDaily ? 'http://www.daily.tmall.net' : 'https://www.tmall.com';
          }
      for(var i=0, len=whiteDomainRegexs.length; i &lt; len; i++) {
          if(whiteDomainRegexs[i].test(domains[2])) { 
              res = url.replace(/&amp;amp;/g, '&amp;');
              break;
          }
      }
      return encodeURIComponent(res);
    }

    var ua = window.navigator.userAgent,
        redirectUrl = lib.getUriQuery('redirect_url') || lib.getUriQuery('redirectURL') || '';
    redirectUrl = checkDomain(redirectUrl);
    //蘋(píng)果safari7下的bug...跳轉(zhuǎn)bug
    if(/AppleWebKit/.test(ua) &amp;&amp; /Version\/7\.0/.test(ua)){
      if(redirectUrl.indexOf('t%3D')&gt;=0){
        redirectUrl.replace(/t\%3D(\d*)/g, function(r){
          return 't%3D' + new Date()*1;
        });
      }else{
        redirectUrl += redirectUrl.indexOf('%3F') &gt;= 0 ? '%26' : '%3F';
        redirectUrl += 't%3D' + new Date()*1;
      }
    }
    //三方cookie 問(wèn)題
    if(/Version\/(\d(?:\.\d+)+)(?:\sMobile\/[0-9a-zA-Z]+)*\\sSafari/.test(ua)){
      document.write('&lt;iframe src="http://www.taobao.com/go/act/login/xd.php" style="display:none;"&gt;&lt;/iframe&gt;');
    }
    
    var proxyUrl = window.lib.isHK ? 'https://www.tmall.hk/wow/import/act/loginproxy?redirectURL=' : 'https://pages.tmall.com/wow/member-club/act/login-proxy?redirectURL=';
    //var tpcUrl = loginHost + '/member/login.jhtml?tpl_redirect_url='  + encodeURIComponent(proxyUrl + redirectUrl);
    var tpcUrl = loginHost + '/member/login.jhtml?tpl_redirect_url=' + redirectUrl;
    tpcUrl = tpcUrl + (redirectUrl.indexOf('sub%3Dtrue') &gt; -1 ? '&amp;sub=true' : '');
    var pms = +new Date(),
        allp = window.lib.isHK ? 'assets_css%3D3.0.6%2Fapps%2Fhk%2Flogin_pc.css' : 'assets_css%3D3.0.10/login_pc.css';
    tpcUrl = tpcUrl + '&amp;style=miniall&amp;enup=true&amp;newMini2=true&amp;full_redirect=true&amp;sub=true&amp;from=tmall&amp;allp=' + allp + '&amp;pms=' + pms;
    
    document.getElementById('J_loginIframe').src = tpcUrl;
</script>

    

<div id="footer" data-spm="a2226n1">



<div id="tmall-desc">
    
        
             
        
    
</div>
<div id="tmall-copyright">
    <div class="mui-global-fragment-load" data-fragment="tmbase/mui_footer_link"></div>
</div>


<div id="server-num">wormholesource011133243006.center.et15.production</div>

</div>

<script type="text/javascript">(function(e){if(!e["_med"])e["_med"]={};var t=e["_med"];t.cookie=function(e,t,a){if(t!==undefined){a=a||{};if(typeof a.expires==="number"){var o=a.expires,l=a.expires=new Date;l.setTime(+l+o864e5)}return document.cookie=[e,"=",String(t),a.expires?"; expires="+a.expires.toUTCString():"",a.path?"; path="+a.path:"",a.domain?"; domain="+a.domain:"",a.secure?"; secure":""].join("")}var r=e?undefined:{};var i=document.cookie?document.cookie.split("; "):[];for(var n=0,s=i.length;n<s;n++){var b=i[n].split("=");var d=b.shift();var p=b.join("=");if(e&&e===d){r=p;break}if(!e&&p!==undefined){r[d]=p}}return r};var a=document;var o=e.devicePixelRatio||1,l=a.documentElement.clientWidth,r=a.documentElement.clientHeight,i,n,s,b=/initial-scale=([d.]+?),/i,d,p;if(a.querySelector){p=a.querySelector('meta[name="viewport"]');if(p){d=b.exec(p.content+",");if(d){s=parseFloat(d[1],10)}}}if(s){l=ls;r=rs}if(screen){if(Math.abs(screen.width-lo)<.2screen.width){l=screen.width/o;r=screen.height/o;i=screen.width;n=screen.height}else{l=screen.width;r=screen.height;i=screen.widtho;n=screen.heighto}}else{i=lo;n=r*o}var m="createTouch"in a&&"ontouchstart"in e?1:0;var c=["dw:"+l,"dh:"+r,"pw:"+i,"ph:"+n,"ist:"+m].join("&");t.cookie("_med",c,{expires:3650})})(window);
</script>

<iframe src="http://g.alicdn.com/alilog/oneplus/blk.html#coid=ei0tEuxEhxcCAXTnnT49Zfbf&amp;noid=&amp;grd=n" id="_oid_ifr_" style="width: 0px; height: 0px; display: none;"></iframe></body></html>

差別非常大,所以想問(wèn)下如何模擬登錄天貓呢~

回答
編輯回答
心沉

天貓頁(yè)面打開(kāi)默認(rèn)是掃碼登錄頁(yè)面
首先執(zhí)行
browser.switch_to.frame("J_loginIframe")
切換到標(biāo)簽
而后執(zhí)行
driver.find_element_by_id('J_Quick2Static').click()
切換到密碼登錄頁(yè)面
輸入用戶名和密碼
點(diǎn)擊提交
driver.find_element_by_id('J_SubmitStatic').click()

2018年1月29日 01:49
編輯回答
糖果果

打開(kāi)默認(rèn)是掃碼界面,登錄框都是隱藏的所以你無(wú)法操作,需要先讓其顯示

2017年5月19日 04:27