读取大.txt并检查响应主体中是否包含字符串

时间:2019-02-28 18:38:42

标签: node.js requestjs

我有此代码:

var fs = require('fs');
var readline = require('readline');
var request = require("request");

var filename = process.argv[2];

readline.createInterface({
    input: fs.createReadStream(filename),
    terminal: false

}).on('line', function(line) {
sep = line.split("|");
id = sep[0];
name = sep[1];

var options = { method: 'POST',
  url: 'https://api.com/mobile_authentications',
  proxy: '...',
  headers: 
   { Host: 'api.com',
     'Content-Type': 'application/json',
     'Accept-Language': 'pt-BR',
     'X-Client-Info': 'Timezone%3D-Infinity%26device_id%3D578e4ac016b69248%26utc_offset%3D-0300%26app_id%3D7092%26resolution%3D720x1280%26connectivity%3DWIFI%26site_id%3DMLB%26density%3D320%26user_id%3Dguest' },
  body: '{"authentication_request":{"client_id":"'+id+'|'+name+'"}}' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);
    if(body.includes('ATTEMPS'))
    {
        console.log("CAPTCHA");
        }
  //console.log(body);
});


});

第一个问题:如何检查正文响应是否包含“ ATTEMPS”字符串?

另一个问题:当ids.txt文件超过100行时,脚本将向我返回此错误:

  if (error) throw new Error(error);
             ^

Error: Error: tunneling socket could not be established, statusCode=502
    at Request._callback (C:\Users\PC\Desktop\top\convert.js:65:20)
    at self.callback (C:\Users\PC\Desktop\top\node_modules\request\request.js:185:22)
    at Request.emit (events.js:182:13)
    at Request.onRequestError (C:\Users\PC\Desktop\top\node_modules\request\request.js:881:8)
    at ClientRequest.emit (events.js:182:13)
    at ClientRequest.onConnect (C:\Users\PC\Desktop\top\node_modules\tunnel-agent\index.js:168:23)
    at Object.onceWrapper (events.js:273:13)
    at ClientRequest.emit (events.js:182:13)
    at Socket.socketOnData (_http_client.js:475:11)
    at Socket.emit (events.js:182:13)

也就是说,脚本不能处理大文件吗? 谢谢。

0 个答案:

没有答案