const metascraper = require('metascraper')([ require('metascraper-author')(), require('metascraper-date')(), require('metascraper-description')(), require('metascraper-image')(), require('metascraper-logo')(), require('metascraper-clearbit')(), require('metascraper-publisher')(), require('metascraper-title')(), require('metascraper-url')() ]) Tengo el siguiente código, pero const no funciona, así que tengo que usar import
import metascraper from 'metascraper'; import title from 'metascraper-title'; import image from 'metascraper-image'; ... Esto no funciona como se esperaba y devuelve indefinido: ¿cómo puedo importar todas esas bibliotecas debajo metascraper usando import . Importarlos manualmente con su propio nombre no funciona.
(async () => { try { // Use the got library to fetch the website content. const targetUrl = 'http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance'; const { body: html, url } = await got(targetUrl); // Extract the metadata from the website content. const metascraper = await metascraper(title(),{ html, url }); // Return the metadata as JSON console.log(JSON.stringify(metascraper)); } catch (err) { console.log(err); } })()Lo siguiente debería funcionar:
import got from "got"; import _metascraper from "metascraper"; import title from "metascraper-title"; import image from "metascraper-image"; import author from "metascraper-author"; // ... const metascraper = _metascraper([title(), image(), author()]); try { // Use the got library to fetch the website content. const targetUrl = "https://wesbos.com/scoped-github-access-token/"; const { body: html, url } = await got(targetUrl); // Extract the metadata from the website content. const metadata = await metascraper({ html, url }); // Return the metadata as JSON console.log(metadata); } catch (err) { console.log(err); }