-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathscrape.js
48 lines (40 loc) · 1.59 KB
/
scrape.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const hooman = require('../');
const assert = require('assert');
const { writeFileSync, statSync } = require('fs');
// Test URL
const hCaptchaPage = 'https://cf-captcha.sayem.eu.org';
const jsChallengePage = 'https://cf-js-challenge.sayem.eu.org';
const fetchHtml = async () => {
const response = await hooman(jsChallengePage);
assert.equal(response.statusCode, 200);
assert.equal(typeof response.body, 'string');
assert.equal(response.isFromCache, false);
assert(response.body.includes('sayem314'));
};
describe('- real world test', () => {
// solve challenge within 20 seconds
it('should return html', fetchHtml).timeout(1000 * 30);
// should fetch within 4 seconds
it('should respect cookies', fetchHtml).timeout(1000 * 4);
it('should download images', async () => {
const response = await hooman(jsChallengePage + '/images/background.jpg', {
responseType: 'buffer',
});
assert.equal(response.statusCode, 200);
assert(Buffer.isBuffer(response.body));
// Write image to file
writeFileSync('image.jpg', response.body);
// Check image size
const { size } = statSync('image.jpg');
assert.equal(size, 31001);
}).timeout(1000 * 5);
if (process.env.CAPTCHA_API_KEY) {
it('should solve captchas', async () => {
const response = await hooman(hCaptchaPage, { captchaKey: process.env.CAPTCHA_API_KEY });
assert.equal(response.statusCode, 200);
assert.equal(typeof response.body, 'string');
assert.equal(response.isFromCache, false);
assert(response.body.includes('sayem314'));
}).timeout(1000 * 200); // 3 min and 20 sec
}
});