![]() ![]() Remember to pass the page's URI as the url option in the JSDOM constructor (as shown in the example above), so that Readability can convert relative URLs for images, hyperlinks etc. Var ) let reader = new Readability ( doc. The function returns a boolean corresponding to whether or not we suspect Readability.parse() will suceeed at returning an article object. visibilit圜hecker (function, default isNodeVisible): the function used to determine if a node is visible.minScore (number, default 20): the minumum cumulated 'score' used to determine if the document is readerable.minContentLength (number, default 140): the minimum node content length used to decide if the document is readerable.Improvements to its logic (while not deteriorating its performance) are very welcome. The reason it exists is to avoid bogging down a time-sensitive process (like loading and showing the user a webpage) with the complex logic in the core of Readability. It is likely to produce both false positives and false negatives. parse ( ) isProbablyReaderable(document, options)Ī quick-and-dirty way of figuring out if it's plausible that the contents of a given document are suitable for processing with Readability. cloneNode ( true ) var article = new Readability ( documentClone ). You can avoid this by passing the clone of the document object to the Readability constructor: This removes some elements in the web page, which may be undesirable. The parse() method works by modifying the DOM. excerpt: article description, or short excerpt from the content.length: length of an article, in characters.textContent: text content of the article, with all the HTML tags removed.content: HTML string of processed article content.Returns an object containing the following properties: If undefined, the default regex is applied. allowedVideoRegex (RegExp, default undefined ): a regular expression that matches video URLs that should be allowed to be included in the article content.It may be useful to specify the serializer as the identity function ( el => el) to obtain a DOM element instead of a string for content if you plan to process it further. serializer (function, default el => el.innerHTML) controls how the the content property returned by the parse() method is produced from the root DOM element.Set this option to true to skip JSON-LD parsing. disableJSONLD (boolean, default false): when extracting page metadata, Readability gives precendence to fields specified in the JSON-LD format.When set to false only classes specified in the classesToPreserve array are kept. keepClasses (boolean, default false): whether to preserve all classes on HTML elements.classesToPreserve (array): a set of classes to preserve on HTML elements when the keepClasses options is set to false.charThreshold (number, default 500): the number of characters an article must have in order to return a result. ![]() ![]() nbTopCandidates (number, default 5): the number of top candidates to consider when analysing how tight the competition is among candidates.no limit): the maximum number of elements to parse. ma圎lemsToParse (number, default 0 i.e.debug (boolean, default false): whether to enable logging.The options object accepts a number of properties, all optional: API Reference new Readability(document, options) In Node.js, you can use an external DOM library. fetched via XMLHttpRequest, in a same-origin you have access to, etc.). If you use Readability in a web browser, you will likely be able to use a document reference from elsewhere (e.g. Var article = new Readability ( document ).
0 Comments
Leave a Reply. |