32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
const fs = require('fs')
|
|
const Horseman = require('node-horseman')
|
|
|
|
const LOGIN_PAGE_URL = 'https://www.amazon.de/ap/signin?showRmrMe=1&openid.return_to=https%3A%2F%2Flayla.amazon.de&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_dp_project_dee_de&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&'
|
|
|
|
const fetchInitialCookies = (jsonCookiesFile, cookiesFile, useragent, user, password, phantomPath) => {
|
|
const horseman = new Horseman({cookiesFile, phantomPath})
|
|
return new Promise((resolve, reject) => {
|
|
horseman
|
|
.userAgent(useragent)
|
|
.open(LOGIN_PAGE_URL)
|
|
.text('#auth-fpp-link-bottom')
|
|
.type('#ap_email', user)
|
|
.type('#ap_password', password)
|
|
.click('[name="rememberMe"]')
|
|
.click('#signInSubmit')
|
|
.waitForNextPage()
|
|
.plainText()
|
|
.then((text) => {
|
|
if (text.search('Anmelden') !== -1) return reject(false)
|
|
})
|
|
.cookies()
|
|
.then(cookies => resolve(fs.writeFileSync(jsonCookiesFile, JSON.stringify(cookies))))
|
|
.close()
|
|
})
|
|
}
|
|
|
|
module.exports = {
|
|
fetchInitialCookies,
|
|
} |