淘客开发者可利用Node.js+selenium webdriver模拟登录阿里妈妈

时间:2018-07-08 22813 主题:淘客开发教程
导读《淘客开发者可利用Node.js+selenium webdriver模拟登录阿里妈妈》要点:$npminstallselenium-webdriver--save
$ npm install selenium-webdriver --save


淘客开发者要模拟登录阿里妈妈是常见的,可利用Node.js+selenium webdriver。

以上是环境必需,下面是代码:不过实际应用,还需要做一些小修改:


var webdriver = require('selenium-webdriver'),

By = webdriver.By,

until = webdriver.until;


//chrome

var driver = new webdriver.Builder()

.forBrowser('firefox')

.build();


var userName = '';

var passwrod = '';

var loginUrl = 'https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&css_style=alimama&from=alimama&redirectURL=http%3A%2F%2Fwww.alimama.com&full_redirect=true&disableQuickLogin=true';

driver.get(loginUrl)

.then(function () {

return driver.findElement(By.id('TPL_username_1')).sendKeys(userName);

})

.then(function () {

return driver.findElement(By.id('TPL_password_1')).sendKeys(passwrod);

})

.then(function () {

return driver.findElement(By.id('J_SubmitStatic')).click();

})

.then(function () {

sleep(8000);

driver.navigate().to('http://pub.alimama.com/');

})

.then(function () {

return driver.manage().getCookies().then(function (cookies) {

var map = buildCookieMap(cookies);

var cookie2 = map.cookie2.value;

return cookie2;

});

})

.then(function (cookie2) {

//cookie2的值

console.log(cookie2);

});


function buildCookieMap(cookies) {

var map = {};

cookies.forEach(function (cookie) {

map[cookie.name] = cookie;

});

return map;

}

function sleep(d) {

for (var t = Date.now(); Date.now() - t <= d;);

}


转载请注明本页网址:https://veapi.cn/taokelianmeng/195.html
淘客/抖客/多多进宝专题

暂无淘宝客专题教程


在线
客服

会员请加QQ群交流:

微信
咨询

加微信咨询
顶部