Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

htmlparser2 extract text from html

const htmlparser2 = require('htmlparser2');

const getText = html => {
    const handler = new htmlparser2.DomHandler();
    const parser = new htmlparser2.Parser(handler);

    parser.write(html);
    parser.end();

    return htmlparser2.DomUtils.textContent(handler.root.childNodes);  // or from handler.dom
};


// Example usage:

const html = '<div><p>This is example text 1</p><br /><p>This is example text 2</p></div>';
const text = getText(html);

console.log(text);

Output:

This is example text 1

This is example text 2
Comment

PREVIOUS NEXT
Code Example
Javascript :: SETTING ADOBE ANALYTICS DEBUGGER 
Javascript :: top-level code javascript 
Javascript :: float force loopback 
Javascript :: Não é possível chamar Veiculo.create(). O método create não foi configurado. O PersistedModel não foi conectado corretamente a uma DataSource! 
Javascript :: node:internal/modules/cjs/loader:936 throw err; ^ 
Javascript :: update object in react hooks 
Javascript :: js check if date object is invalid 
Javascript :: random js 
Javascript :: array loop js 
Javascript :: horizontal scroll onclick react 
Javascript :: js loop over object 
Javascript :: JavaScript check all checkboxes on page 
Javascript :: javascript cookies 
Javascript :: regex password 
Javascript :: appTsConfig.compilerOptions[option] = value; 
Javascript :: how to clear innerhtml in javascript 
Javascript :: jquery when any key is pressed 
Javascript :: javascript parse url parameters 
Javascript :: node.js http request ip address 
Javascript :: js getattribute 
Javascript :: how to make a kill command discord.js 
Javascript :: react js font awesome icon not rendering 
Javascript :: mandelbrot set javascript 
Javascript :: urlencoded json express 
Javascript :: javascript check if string ends with 
Javascript :: align text in js 
Javascript :: js object every 
Javascript :: mongoose nullable 
Javascript :: usehistory example 
Javascript :: vedere se radio button è cliccato js 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =