Skip to content

htmlparser2vsembed

MIT 12 4 4,789
277.1 million (month) Aug 28 2011 12.0.0(2026-03-20 23:08:40 ago)
2,103 6 71 MIT
Oct 26 2013 5.2 thousand (month) v4.4.15(2025-01-02 16:53:09 ago)

htmlparser2 is a Node.js library for parsing HTML and XML documents. It works by building a tree of elements, similar to the Document Object Model (DOM) in web browsers. This allows you to easily traverse and manipulate the structure of the document.

htmlparser2 is a low-level html tree parser but it can still be useful in web scraping as it's a powerful tool for HTML restructuring and serialization.

PHP library to get information from any web page (using oembed, opengraph, twitter-cards, scrapping the html, etc). It's compatible with any web service (youtube, vimeo, flickr, instagram, etc) and has adapters to some sites like (archive.org, github, facebook, etc).

Example Use


```javascript const htmlparser = require("htmlparser2"); const parser = new htmlparser.Parser({ onopentag: (name, attribs) => { console.log(`Opening tag: ${name}`); }, ontext: (text) => { console.log(`Text: ${text}`); }, onclosetag: (name) => { console.log(`Closing tag: ${name}`); } }, {decodeEntities: true}); const html = "

Hello, world!

"; parser.write(html); parser.end(); ```
```javascript use Embed\Embed; $embed = new Embed(); //Load any url: $info = $embed->get('https://www.youtube.com/watch?v=PP1xn5wHtxE'); //Get content info $info->title; //The page title $info->description; //The page description $info->url; //The canonical url $info->keywords; //The page keywords $info->image; //The thumbnail or main image $info->code->html; //The code to embed the image, video, etc $info->code->width; //The exact width of the embed code (if exists) $info->code->height; //The exact height of the embed code (if exists) $info->code->ratio; //The aspect ratio (width/height) $info->authorName; //The resource author $info->authorUrl; //The author url $info->cms; //The cms used $info->language; //The language of the page $info->languages; //The alternative languages $info->providerName; //The provider name of the page (Youtube, Twitter, Instagram, etc) $info->providerUrl; //The provider url $info->icon; //The big icon of the site $info->favicon; //The favicon of the site (an .ico file or a png with up to 32x32px) $info->publishedTime; //The published time of the resource $info->license; //The license url of the resource $info->feeds; //The RSS/Atom feeds ```

Alternatives / Similar


Was this page helpful?