Как использовать прокси с nodejs - PullRequest
0 голосов
/ 29 июня 2018

Я пытаюсь очистить сайт "https://shmoti.com", но, похоже, они заблокировали мой ip. Поэтому я пытаюсь использовать прокси с node.js.

Я использую модуль node-fetch для получения html тела сайта.

Как использовать прокси с node-fetch? Также я не знаю, где взять такие бесплатные прокси. Любая помощь с этим?

Мне нужно использовать сам модуль fetch , так как я делаю всю свою обработку асинхронным способом.

1 Ответ

0 голосов
/ 29 июня 2018

https://github.com/bitinn/node-fetch#options

это говорит, что из их документации

{
// These properties are part of the Fetch Standard
method: 'GET',
headers: {},        // request headers. format is the identical to that accepted by the Headers constructor (see below)
body: null,         // request body. can be null, a string, a Buffer, a Blob, or a Node.js Readable stream
redirect: 'follow', // set to `manual` to extract redirect headers, `error` to reject redirect

// The following properties are node-fetch extensions
follow: 20,         // maximum redirect count. 0 to not follow redirect
timeout: 0,         // req/res timeout in ms, it resets on redirect. 0 to disable (OS limit applies)
compress: true,     // support gzip/deflate content encoding. false to disable
size: 0,            // maximum response body size in bytes. 0 to disable
agent: null         // http(s).Agent instance, allows custom proxy, certificate, lookup, family etc.

}

так что, вероятно, вы могли бы попробовать

fetch('example.com',{
        agent: new HttpsProxyAgent('http://127.0.0.1:8580')
    }).then(function(res){
    ...
})
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...