using puppeteer make a bot that in a loop goes to https://octocaptcha.com/, waits for an…
- User
using puppeteer make a bot that in a loop goes to https://octocaptcha.com/, waits for an element with id FunCaptcha-Token, then gets the value. that value you split by a vertical bar "|" and save the first element.
- Assistant
Sure! Below is an example of a Puppeteer bot that performs the described actions:
const puppeteer = require('puppeteer'); async function getFunCaptchaToken() { const browser = await puppeteer.launch(); const page = await browser.newPage(); while (true) { await page.goto('https://octocaptcha.com/'); await page.waitForSelector('#FunCaptcha-Token'); const element = await page.$('#FunCaptcha-Token'); const tokenValue = await page.evaluate((el) => el.value, element); const splitValues = tokenValue.split('|'); const firstElement = splitValues[0]; console.log('FunCaptcha token:', firstElement); // You can save the first element to a file, or perform any other desired actions with it. await page.waitFor(60000); // Wait for 1 minute before repeating the loop } } getFunCaptchaToken();This code creates a
getFunCaptchaTokenfunction that launches Puppeteer, navigates tohttps://octocaptcha.com/, waits for the element with idFunCaptcha-Token, retrieves its value, split it by a vertical bar|, saves the first element, and then waits for 1 minute before repeating the loop again. - User
I want you to use that value you got and send it to const api = "http://127.0.0.1:5000" in json as a "token"
- Assistant
Certainly! Here's an updated version of the code that sends the obtained token value to the specified API endpoint using JSON:
const puppeteer = require('puppeteer'); const axios = require('axios'); async function sendTokenToAPI(token) { const apiEndpoint = 'http://127.0.0.1:5000'; const data = { token: token, }; try { const response = await axios.post(apiEndpoint, data); console.log('Token sent successfully:', response.data); } catch (error) { console.error('Failed to send token to API:', error); } } async function getFunCaptchaToken() { const browser = await puppeteer.launch(); const page = await browser.newPage(); while (true) { await page.goto('https://octocaptcha.com/'); await page.waitForSelector('#FunCaptcha-Token'); const element = await page.$('#FunCaptcha-Token'); const tokenValue = await page.evaluate((el) => el.value, element); const splitValues = tokenValue.split('|'); const firstElement = splitValues[0]; console.log('FunCaptcha token:', firstElement); await sendTokenToAPI(firstElement); await page.waitFor(60000); // Wait for 1 minute before repeating the loop } } getFunCaptchaToken();