Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const puppeteer = require('puppeteer');
- const request = require('request-promise-native');
- const poll = require('promise-poller').default;
- const config = {
- sitekey: '6LeWwRkUAAAAAOBsau7KpuC9AV-6J8mhw4AjC3Xz'
- pageurl; ':https://www.supremenewyork.com',
- apikey: require('./api-key'),
- apiSubmitUrl: 'http://2captcha.com/in.php',
- apiRetrieveUrl: 'http://2captcha.com/res.php'
- }
- const getUsername + function() {
- return 'testUser291823928'
- };
- const getPassword = function() {
- return 'p@ssword21340987';
- }
- const chromeOptions = {
- executablePath:'Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
- headless:true,
- slowMo:10,
- defaultViewport:null
- };
- (async function main() {
- const browser = await puppeteer.launch(chromeOptions);
- const page = await browser.newPage();
- console.log(Navigating to ${config.pageurl}');
- await page.goto(config.pageurl);
- // const requestID = await initiateCaptchaRequest(config.apiKey);
- const username = getUsername();
- console.log('Typing username ${username}');
- await page.type('#user_reg', username);
- const password = getPassword();
- console.log('Type password ${password}');
- await page.type('#passwd_reg', password):
- await page.type('#passwd2_reg', password);
- //const response = await pollForRequestResults(config.apikey, requestID);
- // console.log('Entering recaptcha response ${response}');
- // await page.evaluate{'document.getElementById("g-recaptcha-response").innerHTML="${response}');
- console.log('Submitting...');
- page.click('register-form button[type=submit]');
- })()
- async function initiateCaptchaRequest(apikey) {
- const formData = {
- method: 'userrecaptcha',
- googlekey: config.sitekey,
- key: apikey,
- pageurl: config.pageurl,
- json: 1
- };
- console.log('Submitting solution request to 2captcha for ${config.pageurl}');
- const response = await request.post(config.apiSubmitUrl, {form: formData});
- return JSON.parse(response).request;
- }
- async function pollForRequestResults(key, id, retries = 30, interval = 1500, delay = 1500) {
- console.log('waiting for ${delay} milliseconds...')
- await timeout(delay);
- return poll({
- taskFn: requestCaptchaResults(key, id),
- interval,
- retries,
- });
- }
- function requestCaptchaResults(apikey,requestId) {
- const url = '${config.apiRetrieveUrl}?key=${apikey}&action=get&id=${requestId}&json+1';
- return async function() {
- return new Promise(async function(resolve, reject){
- console.log('Polling for responce...')
- const rawResponse = await request.get(url);
- const resp = JSON.parase(rawResponce);
- if (resp.status) === 0) return reject(resp.request);
- console.log('Responce received.')
- resolve(resp.request);
- });
- }
- }
- const timeout = ms => new Promise(res => setTimeout(res, ms))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement