Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jssoup

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jssoup

JSSoup is a BeautifulSopu style HTML parser library.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.2K
decreased by-11.06%
Maintainers
1
Weekly downloads
 
Created
Source

JSSoup

I'm a fan of Python library BeautifulSoup. It's feature-rich and very easy to use. But when I am working on a small react-native project, and I tried to find a HTML parser library like BeautifulSoup, I failed.
So I want to write a HTML parser library which can be so easy to use just like BeautifulSoup in Javascript.
JSSoup uses tautologistics/node-htmlparser as HTML dom parser, and creates a series of BeautifulSoup like API on top of it.

Naming Style

JSSoup tries to use the same interfaces as BeautifulSoup so BeautifulSoup user can use JSSoup seamlessly. However, JSSoup uses Javascript's camelCase naming style instead of Python's underscore naming style. Such as find_all() in BeautifulSoup is replaced as findAll().


How to use JSSoup

Make Soup

var soup = JSSoup('<html><head>hello</head></html>');

Navigation

.previousElement, .nextElement
var data = `
<div>
  <a>1</a>
  <b>2</b>
  <c>3</c>
</div>
`
var soup = JSSoup(data);
var div = soup.nextElement;
var b = div.nextElement.nextElement;
// b.string: '2'
var a = b.previousElement;
// a.string: '1'
.previousSibling, .nextSibling
var soup = JSSoup(data);
var div = soup.nextElement;
var a = div.nextElement;
var b = a.nextSibling;
var c = b.nextSibling;
c.nextSibling == undefined;
.contents
div.contents
// [<a>1</a>, <b>2</b>, <c>3</c>]
.descendants
div.descendants
// [<a>1</a>, 1, <b>2</b>, 2, <c>3</c>, 3]
.parent
div.parent == soup
.getText(), .text
div.text
// '123'
div.getText('|')
// '1|2|3'
.string
b.string == '2';
var soup = JSSoup('<html><head>hello</head></html>');
soup.string == 'hello';

Edit

.extract()
b.extract();
div.contents
// [<a>1</a>, <b>2</b>, <c>3</c>]
.findAll()
var data = `
<div>
  <div class="h1"></div>
  <a>hello</a>
</div>
`
var soup = JSSoup(data);
soup.findAll('a')
// [<a>hello</a>]
soup.findAll('div', 'h1')
// [<div class="h1"></div>]

Run Test

npm test

Status

There's a lot of work need to be done.

Keywords

FAQs

Package last updated on 12 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc