项目作者: sayem314

项目描述 :
http interceptor to hoomanize cloudflare requests
高级语言: JavaScript
项目地址: git://github.com/sayem314/hooman.git
创建时间: 2020-05-03T21:25:12Z
项目社区:https://github.com/sayem314/hooman

开源协议:MIT License

下载


" class="reference-link">hooman JS-Challange

HTTP interceptor using got to bypass Cloudflare DDOS protection / JavaScript challenge on Node.js

JS-Challange hCaptcha

hooman is not meant for spamming, please use it sanely.

Install

  1. # with npm: npm i hooman got
  2. yarn add hooman got

got is peer-dependency

Usage Example

GET HTML
  1. const hooman = require('hooman');
  2. (async () => {
  3. try {
  4. const response = await hooman.get('https://sayem.eu.org');
  5. console.log(response.body);
  6. //=> '<!doctype html> ...'
  7. } catch (error) {
  8. console.log(error.response.body);
  9. //=> 'Internal server error ...'
  10. }
  11. })();
POST JSON
  1. const { body } = await hooman.post('https://httpbin.org/anything', {
  2. json: {
  3. hello: 'world',
  4. },
  5. responseType: 'json',
  6. });
  7. console.log(body.data);
  8. //=> {hello: 'world'}
Pipe Stream
  1. // This is mandatory to set cookie first since .stream() doesn't fire hooks
  2. await hooman(jsChallengePage);
  3. // Now we can download files
  4. const image = fs.createWriteStream('image.jpg');
  5. hooman.stream(imageUrl).pipe(image);
Captcha
  1. const response = await hooman.get(url, {
  2. captchaKey: '2captcha_or_rucaptcha_api_key',
  3. rucaptcha: true | false, // optional (default false)
  4. });
  5. console.log(response.body);

You can also set environment variable HOOMAN_CAPTCHA_KEY and HOOMAN_RUCAPTCHA

All you need to do is provide captchaKey and rest is done by hooman. It automatically detects if g/hCaptcha is present and need solving or can be solved. There are console.log print on hit as well.

Note that if you make multiple request to same site at once only the first request will be sent for captcha solving while other request will be hanged until captcha is solved. You might face multiple trigger to captcha, please monitor your usage. Best practice is to make a dummy request first and let hooman solve captcha and then process further requests.

Custom Captcha Handling
  1. const response = await hooman.get(url, {
  2. // required
  3. captchaKey: 'your_captcha_api_key',
  4. // use with captchaKey, should return captcha response string or undefined
  5. onCaptcha: ({ key, pageurl, sitekey, method }) => {
  6. // solve captcha here
  7. return h_captcha_response;
  8. },
  9. });
  10. console.log(response.body);
Proxy
  1. const HttpsProxyAgent = require('https-proxy-agent');
  2. const proxy = new HttpsProxyAgent('http://127.0.0.1:3128');
  3. const response = await hooman('https://sayem.eu.org', {
  4. agent: {
  5. https: proxy,
  6. },
  7. });

API

Please see available API here.

All methods and props of got should work fine.

Support

If you open any issue, please respect issue template and provide clean and re-producible example code which can be run without any modification. Low effort issue will be ignored.


I don’t make any profit with this library. If you want to show your appreciation, you can donate me here :scream_cat: Thanks! You can also hire me for scraping solution, ping me and we will discuss further :smile:

Made with :heart: & :coffee: by Sayem