Tjatse / node-readability

Scrape/Crawl article from any site automatically. Make any web page readable, no matter Chinese or English.
341 stars 36 forks source link

[Discussion] About using node.score instead node.data() method #37

Closed midudev closed 2 years ago

midudev commented 8 years ago

After done some research I'm looking about node.data(). Would it be a good idea to extend the node element object with a property score instead using the DOM to store the score and grab it again using Cheerio?

From my understanding I see some benefits:

What do you think @Tjatse?

Tjatse commented 8 years ago

node.data('score') equals node.data.score So, whats the difference between node.data.score and node.score?

midudev commented 8 years ago

Actually, under the hood, there's a lot more done than this. You can take a look to the documentation of Cheerio for readData, setData and data: https://github.com/cheeriojs/cheerio/blob/master/lib/api/attributes.js

It does some unnecessary checks for our intentions, loop, store data on a internal cache, ...

I would say that kind of methods are intended to manipulate HTML5 data-attributes, which is great, but in that specific case (that's not being used here for that intention) could be simplified to a fastest access by simply giving to the node a new property.

Tjatse commented 8 years ago

It makes sense :)