Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
Nodo JS Insertar texto del archivo para nombrar el archivo de resultados de la chatarra de Titiritero

Estoy pirateando un script de nodo en Puppeteer donde elimino una página web y aseguro el contenido como un archivo de texto donde nombro el archivo después de la fecha y quiero agregar texto de un archivo de texto al final del nombre.

 const puppeteer = require('puppeteer'); const fs = require('fs'); let utc_date_string = new Date().toLocaleString("en-US", { timeZone: "UTC" }); let date_utc = new Date(utc_date_string); let year = date_utc.getFullYear(); let month = ("0" + (date_utc.getMonth() + 1)).slice(-2); let date = ("0" + date_utc.getDate()).slice(-2); let hours = ("0" + date_utc.getHours()).slice(-2); let minutes = ("0" + date_utc.getMinutes()).slice(-2); let time_hh_mm = hours + + minutes; let data = fs.readFileSync('insert.txt', 'utf8'); (async () => { const browser = await puppeteer.launch( { headless: true, args: ['--single-process', '--no-zygote', '--no-sandbox'] }) const page = await browser.newPage() await page.goto('https://example.com/xxx.html') const myproblem = await page.$eval('table', table => table.innerText) fs.writeFile('/var/www/mydomain.com/xxx/'+year+'-'+month+'-'+date+'-'+time_hh_mm+'-'+data+'.txt', myproblem) await browser.close() })()

Esto funciona hasta ahora, pero el problema es que el nombre del archivo sale así

 '2022-02-13-1453-test_text_insert'$'\n''.txt'

y no así

 2022-02-13-1453-test_text_insert.txt

Si uso solo la fecha, el nombre del archivo sale como se esperaba. No sé de dónde vienen los caracteres adicionales (no están en el archivo de texto) o si hay algún problema con el código.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Error de cadena. Deberías revisar esta línea:

 let time_hh_mm = hours + + minutes;

Tal vez debería ser así: (?)

 let time_hh_mm = hours + minutes;

Y trató de leer el archivo que contiene el carácter de línea de corte \n , puede intentar recortarlo.

 fs.writeFile('/var/www/mydomain.com/xxx/'+year+'-'+month+'-'+date+'-'+time_hh_mm+'-'+data.trim()+'.txt', myproblem)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!