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'
Run
npm install
command to install dependent packages. I think dependent packages are not properly installed.
Remove the nodeModules from your solution folder structure and then try to install npm-install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With