0
const url = 'https://www.benzinga.com/stock/aapl/';
const url1 = 'https://www.benzinga.com/stock/msft/';
const url2 = 'https://www.benzinga.com/stock/mu/';

axios.all([
  axios.get(url),
  axios.get(url1),
  axios.get(url2)

 ])
  .then(axios.spread((url11, url12, url13) => {

    async function scraper() {

    try{
      var benzinga1 = url11;
        return benzinga1;

      } catch (err) {
        console.error(err);
    }
  };
  scraper();

  async function scraper1() {

    try{
      var benzinga2 = url12;
      return benzinga2;

      } catch (err) {
        console.error(err);
    }
  };
  scraper1();

  async function scraper2() {

    try{
      var benzinga3 = url13;
      return benzinga3;

      } catch (err) {
        console.error(err);
    }
  };
  scraper2();

async function final() {

  try{
      console.log(mybenzinga1);
      } catch (err) {
        console.error(err);
    }
  };
final();

}))
  .catch((error) => {
   next(error);
  });

when saving url11 to the file it writes [Object object] how to derive a line from a promise.

I can not understand how to convert to a string and save the value to a file

when saving url11 to the file it writes [Object object] how to derive a line from a promise.

I can not understand how to convert to a string and save the value to a file

novikov433
  • 23
  • 5
  • 1
    Does this answer your question? [Converting an object to a string](https://stackoverflow.com/questions/5612787/converting-an-object-to-a-string) – Makdous Apr 25 '20 at 09:35
  • no it didn't help https://ibb.co/wrn36cC https://jsfiddle.net/novikov433/exz8ac03/1/ – novikov433 Apr 25 '20 at 09:48

1 Answers1

1

Try This

    const axios = require("axios");
    const fs = require('fs').promises;
    const url = 'https://www.benzinga.com/stock/aapl/';
    const url1 = 'https://www.benzinga.com/stock/msft/';
    const url2 = 'https://www.benzinga.com/stock/mu/';

    axios.all([
        axios.get(url),
        axios.get(url1),
        axios.get(url2)

    ]).then((data) => {
        data.map(async (item, index) => {
            try {
                await fs.writeFile(`index${index}.html`, item.data);
            } catch (e) {
                console.log(e);
            }
        });
    }).catch((error) => {
        next(error);
    });
Rahul Kumar
  • 144
  • 8