【问题标题】:Add 2 Line-By-Line text readers in one function在一个功能中添加 2 个逐行文本阅读器
【发布时间】:2020-02-15 08:42:03
【问题描述】:

我想读取 2 个不同的文本文件,keys.txt 文件和 proxies.txt 文件。在读取 keys.txt 时启动一个函数并读取 proxies.txt 以在该函数中添加一些内容。

var LineByLineReader = require('line-by-line'),
    lr = new LineByLineReader('keys.txt');
    ls = new LineByLineReader('proxies.txt')


lr.on('line', function (line) {
    console.log(chalk.blueBright("Going next to: " + line))
    lr.pause();
     x = x+1  //ignore this, it is my max readers per second
    if(x<=10){ 
        try {
    (async () => {
       ls.on('line', proxy) .then(proxy => { 
        const browser = await puppeteer.launch({headless: true, devtools: false,
            args: [`--proxy-server=http://${proxy}`]
        })
        const page = await browser.newPage()

       })})} catch(err) {throw(err)}}})

我需要在我的代码中使用 proxies.txt 中的行,但是我不能这样做,因为它启动了 2 个单独的函数。 (如果我使用ls.on('line', function proxy { CODE }))。出于某种原因,ls.on('line', proxy) .then(proxy =&gt; { 行似乎无法正常工作。

【问题讨论】:

    标签: javascript node.js proxy puppeteer line-by-line


    【解决方案1】:

    我做到了。我用过

    ls.on('line', (proxy) => {
        ls.pause();
    

    在代码之前。现在对于每一行,它会逐行读取两个文本文件,并执行我需要的函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-05
      相关资源
      最近更新 更多