untitled notebook

node v8.17.0
version: 2.0.0
endpointsharetweet
const http = require('http'), request = require('request'), fetch = require('node-fetch'), cheerio = require('cheerio') FormData = require("form-data") const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16.6) AppleWebKit/538.11.19 (KHTML, like Gecko) Chrome/61.0.3087.76 Safari/538.11.19' const headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-US,en;q=0.8', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'DNT': '1', 'Pragma': 'no-cache', 'Upgrade-Insecure-Requests': 1, 'User-Agent': userAgent, } // var request = require('request');
// http.createServer().listen('3000', () => console.log('Feeling good at 3000')) async function test(){ return await getX() } async function getX(){ const validate = await goto('https://hh.ru/'), cookie = getCookie(validate), loginPage = await goto('https://m.hh.ru/account/login', { headers: {cookie}}), loginPageHtml = cheerio.load(await getHtml(loginPage)), form = new FormData() form.append('_xsrf', loginPageHtml('input[name=_xsrf]').val()) form.append('email', 'hr01@eurus.global') form.append('password', 'Ab2K,;#a') const login = await goto('https://m.hh.ru/account/login?backurl=%2F', { headers: { ...loginPage.headers, method: 'POST', cookie: getCookie(loginPage), 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', body: form, } }) // console.log(xsrf, cookie, getCookie(login)) console.log(await getHtml(login)) // console.log(new FormData(loginPageHtml('[data-qa=account-login-form]'))) } function getCookie(response){ return response.headers._headers['set-cookie'] } function getRedirect(response){ return response.headers.get('location') } async function getHtml(response){ return await response.text() } async function goto(url, options = {}){ const _url = url, _options = options return await fetchUrl() async function fetchUrl(url = _url, options = _options){ const response = await fetch(url, { method: 'GET', headers, credentials: 'include', redirect: 'manual', // mode: 'cors', ...options, }) const redirect = getRedirect(response), cookie = getCookie(response) if(response.status === 302 && redirect !== _url /*'https://hh.ru/'*/) { // console.log('***********************************************'); // console.log(redirect + '\n' + response.status + '\n' + cookie) // console.log('***********************************************'); return await fetchUrl(redirect, { headers: { ...headers, cookie } }) } return await fetch(redirect, { method: 'GET', headers, credentials: 'include', redirect: 'manual', // mode: 'cors', ...options, }) // console.log('Final Result'); // console.log(resp.status); } }
test()
// async function login(){ // const { cookie, xsrf, requestId } = await getX() // console.log({ cookie, xsrf, requestId }) // return // const form = new FormData() // form.append('username', '***') // form.append('password', '***') // form.append('remember', 'yes') // form.append('backUrl', 'https://hh.ru/') // form.append('failUrl', '/account/login?backurl=%2F') // form.append('_xsrf', xsrf) // const response = await fetch('https://m.hh.ru/account/login', { // method: 'POST', // body: form, // credentials: 'include', // redirect: 'follow', // mode: 'cors', // headers: { // ...headers, // 'Content-Type': 'application/x-www-form-urlencoded', // 'Referer': 'https://hh.ru/login', // 'Cache': 'no-cache', // 'X-Request-ID': requestId, // cookie, // } // }) // const cookieNew = response.headers.get('set-cookie') // const html = await response.text() // console.log(html) // } // const response = await fetch('https://m.hh.ru/account/login', { // method: 'GET', // headers, // credentials: 'include', // redirect: 'manual', // mode: 'cors', // }) // const html = await response.text() // const $ = cheerio.load(html) // const xsrf = $('input[name=_xsrf]').val() // const cookie = response.headers.get('set-cookie') // const redirect = response.headers.get('location') // const requestId = response.headers.get('x-request-id') // console.log(response) // return { cookie, xsrf, requestId }
Loading…

no comments

    sign in to comment