用selenium的原因就是因為他可以加載JS,可以獲得我們在瀏覽時一樣的源碼.
但是在用python+selenium打開天貓登錄頁時https://login.tmall.com/,用drivezr.page_source()輸出的源碼和在網(wǎng)頁上看是不一樣的.
在網(wǎng)頁用F12打開可以看到,源碼是
但是如果是用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=&userid=&aplus&yunid=&&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('&'),
value, stop;
for(var i=0, len=querys.length; i < 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') >= 0) {
location.href = l95095;
} else if(ref.indexOf('liangxinyao.com') >= 0) {
location.href = lliangxinyao
}
window.lib.isDaily = location.href.indexOf('daily.tmall.net') > -1 ? true : false;
window.lib.isHK = location.href.indexOf('login.tmall.com') <= -1 && location.href.indexOf('pre-wormhole.tmall.com') <= -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="夏普超級品牌日">
<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&style=miniall&enup=true&newMini2=true&full_redirect=true&sub=true&from=tmall&allp=assets_css%3D3.0.10/login_pc.css&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 > 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 && 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';
// 檢測白名單
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 < len; i++) {
if(whiteDomainRegexs[i].test(domains[2])) {
res = url.replace(/&amp;/g, '&');
break;
}
}
return encodeURIComponent(res);
}
var ua = window.navigator.userAgent,
redirectUrl = lib.getUriQuery('redirect_url') || lib.getUriQuery('redirectURL') || '';
redirectUrl = checkDomain(redirectUrl);
//蘋果safari7下的bug...跳轉(zhuǎn)bug
if(/AppleWebKit/.test(ua) && /Version\/7\.0/.test(ua)){
if(redirectUrl.indexOf('t%3D')>=0){
redirectUrl.replace(/t\%3D(\d*)/g, function(r){
return 't%3D' + new Date()*1;
});
}else{
redirectUrl += redirectUrl.indexOf('%3F') >= 0 ? '%26' : '%3F';
redirectUrl += 't%3D' + new Date()*1;
}
}
//三方cookie 問題
if(/Version\/(\d(?:\.\d+)+)(?:\sMobile\/[0-9a-zA-Z]+)*\\sSafari/.test(ua)){
document.write('<iframe src="http://www.taobao.com/go/act/login/xd.php" style="display:none;"></iframe>');
}
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') > -1 ? '&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 + '&style=miniall&enup=true&newMini2=true&full_redirect=true&sub=true&from=tmall&allp=' + allp + '&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&noid=&grd=n" id="_oid_ifr_" style="width: 0px; height: 0px; display: none;"></iframe></body></html>
差別非常大,所以想問下如何模擬登錄天貓呢~
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
北大青鳥中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。