I'm using Angular 6 and scraperjs.
and in my component file, used the code given in the example like
import { Component, OnInit } from '@angular/core';
import scraperjs from 'scraperjs';
@Component({
selector: 'app-express',
templateUrl: './express.component.html',
styleUrls: ['./express.component.css']
})
export class ExpressComponent implements OnInit {
constructor() { }
ngOnInit() {
this.aliExpress();
}
aliExpress() {
console.log('loaded ali express');
scrapperjs.StaticScraper.create('https://news.ycombinator.com')
.scrape(function ($) {
return $('.title a').map(function () {
return $(this).text();
}).get();
}).then(function (news) {
console.log(news);
});
}
}
but it is giving error as
Failed to compile.
./node_modules/cheerio/index.js
Module not found: Error: Can't resolve './package' in '/home/user/code/angular/ali-express/node_modules/cheerio'
require()at run-time. There has to be a configured module loader that knows where to load files from. The defaultrequire()created by WebPack will only map to modules that exist in the bundles. Either make sure they are added to the bundles. Configure a different loader (like SystemJS) or useimport.import scraperjs from 'scraperjs';at top and removedrequire, still same error.npm install --save-dev cheerio