Giter Club home page Giter Club logo

ssoup's Introduction

ssoup: Scala CSS Selector DSL based on jsoup

Install

"info.henix" %% "ssoup" % "0.5"
  • DO NOT use v0.3

Example

import henix.ssoup.Selectors
import Selectors._

val document = Jsoup.parse(???)
val body = select1(document |>> "body") // BFS will find <body> more quickly than DFS
val nav = select(body > "div#page" > "div#nav").headOption

val $ = Selectors.buildIdCache(document)
val footer = $("footer")

Notice

  • Structural selectors not allowed in string parameters: select(body > "#page > #nav") won't do what you expect. String parameters only allow selectors for a single HTML element.

Supported structural selectors

  • > : child
  • >> : traverse descendants using DFS
  • |>> : traverse descendants using BFS
  • ~ : siblings
  • + : immediate sibling

API

select(Iterator[Element]): Stream[Element]

Find all elements that match the selector.

select1(Iterator[Element]): Element

Find the first element that matches the selector. This macro will generate friendly error message which include the selector.

Performance Consideration

In contrast to many selectors implementations, ssoup implement selectors in a more direct way. This means:

  • > will iterate element's children
  • ~ will iterate element's siblings
  • >> and |>> will traverse element's all descendants

So you should avoid using more than one >> or |>> in a select / select1 call.

ssoup's People

Contributors

henix avatar

Stargazers

Lunfu Zhong avatar Sergiusz Kierat avatar Pavel avatar ScalaWilliam avatar Sam Wigley avatar Bartłomiej Szałach avatar Onilton Maciel avatar Felipe Hummel avatar Odd Möller avatar  avatar

Watchers

 avatar Onilton Maciel avatar ScalaWilliam avatar Sam Wigley avatar

ssoup's Issues

Update deps

There will be nice to have updated dependencies :

  • jsoup
  • sbt
  • scala 2.13

dfsTraverse 性能提升

线上用 VisualVM sampler 发现 Iterator 的某个匿名中的 Iterator 的 hasNext 占用 CPU 较高。故考虑优化一下 dfsTraverse 中的 Iterator 使用。

采用 ScalaMeter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.