CCT / index.js
cfoo
Update index.js
a734869 verified
// Import the modules
const express = require('express');
const axios = require('axios');
// Create an express app
const app = express();
// Define a route for the root path
app.all('/', async (req, res) => {
// Initialize a counter for the loop
let count = 0;
// Initialize a flag for the success
let success = false;
// Loop until success or 10 times
while (!success && count < 10) {
try {
// Fetch the cookies from the given URL
let response = await axios.get('https://getcaptcha.nbing.eu.org/turing/captcha/challenge');
//let response = await axios.get('https://bing.cf03-b29.workers.dev/turing/captcha/challenge');
// Set the success flag to true
success = true;
// Get the cookies from the response header
let cookies = response.headers['set-cookie'];
// Remove all the "Path=/" from the cookies
//cookies = cookies.map(cookie => cookie.replace('Path=/', ''));
// Join the cookies with semicolons
//cookies = cookies.join('; ');
cookies = cookies.map(cookie => cookie.split(';')[0]).join(';');
// Return the cookies as the body of the response
res.send(cookies); // 这里使用res.send方法,而不是res.json方法
} catch (error) {
// Increment the counter
count++;
}
}
// If the loop ends without success, return an error message
if (!success) {
res.status(500).send('Failed to get cookies');
}
});
// Run the express app, listen on port 7860
app.listen(7860, () => {
console.log('App is running on port 7860');
});