문제

I'm currently using NodeJS to scrap a web page with the following modules: Cheerio and Request

Is it possible to use the css() jQuery function in NodeJS ?

request({uri: website}, function(error, response, body) {

  var $ = cheerio.load(body);
  myItemColor = $('.myitem').css('color');
  console.log(myItemColor);

});

I would like to retrieve a css property of a given jQuery object.

Thanks for your help!

도움이 되었습니까?

해결책

Yes, it is.

But you need to run jQuery inside a DOM so that this works. Check out my jQuery on the server sample, especially this part of the app.js file to see how you can use jsdom to create a server-side DOM for a download HTML site.

PS: I haven't tried it, but it should work with the css function as well (I don't see any reason why it shouldn't).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top