最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

[在一个功能中添加2个逐行文本阅读器

IT培训 admin 13浏览 0评论

[在一个功能中添加2个逐行文本阅读器

我想读取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 => {行似乎不起作用。

回答如下:

我做到了。我用过

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

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

[在一个功能中添加2个逐行文本阅读器

我想读取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 => {行似乎不起作用。

回答如下:

我做到了。我用过

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

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

发布评论

评论列表 (0)

  1. 暂无评论