Answer the question
In order to leave comments, you need to log in
How to download captcha image?
Using the http or request module, you need to download the captcha image.
const request = require('request');
const uri = 'https://ext.captcha.yandex.net/image?key=001H7F4Pt8xuKG6qu8iZQHJxXHaANjOE';
request.head(uri, function(err, res, body){
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream('cap.gif'));
});
content-type: undefined
content-length: undefined
const https = require('https');
const fs = require('fs');
https.get('https://ext.captcha.yandex.net/image?key=001H7F4Pt8xuKG6qu8iZQHJxXHaANjOE', function(response){
response.pipe(fs.createWriteStream('captcha.gif'));
});
Answer the question
In order to leave comments, you need to log in
const fs = require('fs');
const { resolve } = require('path');
const { promisify } = require('util');
const writeFile = promisify(fs.writeFile);
const got = require('got');
async function getImage(url)
{
try
{
const { body, statusCode, statusMessage } = await got(url, { encoding: null });
if (statusCode === 200)
{
await writeFile(resolve('.', 'newCaptchaAnchor.gif'), body);
}
else
{
throw new Error(statusMessage);
}
}
catch(err)
{
throw new Error(err);
}
}
getImage('https://developers.google.com/recaptcha/images/newCaptchaAnchor.gif')
.then(() => console.log('Complete....'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question