All Projects → mischov → Meeseeks

mischov / Meeseeks

Licence: other
An Elixir library for parsing and extracting data from HTML and XML with CSS or XPath selectors.

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Meeseeks

Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (+254.76%)
Mutual labels:  xml, parser, xpath
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-67.46%)
Mutual labels:  xml, parser, xpath
Harser
Easy way for HTML parsing and building XPath
Stars: ✭ 135 (-46.43%)
Mutual labels:  parser, xpath
Omniparser
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
Stars: ✭ 148 (-41.27%)
Mutual labels:  xml, parser
Gelatin
Transform text files to XML, JSON, or YAML
Stars: ✭ 150 (-40.48%)
Mutual labels:  xml, parser
Sax Wasm
The first streamable, fixed memory XML, HTML, and JSX parser for WebAssembly.
Stars: ✭ 89 (-64.68%)
Mutual labels:  xml, parser
Markup
A Swift package for working with HTML, XML, and other markup languages, based on libxml2.
Stars: ✭ 93 (-63.1%)
Mutual labels:  xml, xpath
Ono
A sensible way to deal with XML & HTML for iOS & macOS
Stars: ✭ 2,599 (+931.35%)
Mutual labels:  xml, xpath
Oga
Read-only mirror of https://gitlab.com/yorickpeterse/oga
Stars: ✭ 1,147 (+355.16%)
Mutual labels:  xml, parser
Jquery Xpath
jQuery XPath plugin (with full XPath 2.0 language support)
Stars: ✭ 173 (-31.35%)
Mutual labels:  xml, xpath
Xquery
Extract data or evaluate value from HTML/XML documents using XPath
Stars: ✭ 155 (-38.49%)
Mutual labels:  xml, xpath
Parse Xml
A fast, safe, compliant XML parser for Node.js and browsers.
Stars: ✭ 184 (-26.98%)
Mutual labels:  xml, parser
Jsoup
jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
Stars: ✭ 9,184 (+3544.44%)
Mutual labels:  xml, xpath
Graphquery
GraphQuery is a query language and execution engine tied to any backend service.
Stars: ✭ 112 (-55.56%)
Mutual labels:  xml, xpath
Xmlparser
A low-level, pull-based, zero-allocation XML 1.0 parser.
Stars: ✭ 73 (-71.03%)
Mutual labels:  xml, parser
Xml2lua
XML Parser written entirely in Lua that works for Lua 5.1+. Convert XML to and from Lua Tables 🌖💱
Stars: ✭ 150 (-40.48%)
Mutual labels:  xml, parser
Pugixml
Light-weight, simple and fast XML parser for C++ with XPath support
Stars: ✭ 2,809 (+1014.68%)
Mutual labels:  xml, xpath
Xqerl
Erlang XQuery 3.1 Processor
Stars: ✭ 44 (-82.54%)
Mutual labels:  xml, xpath
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+305.16%)
Mutual labels:  xml, parser
Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (+669.44%)
Mutual labels:  xml, xpath

Meeseeks

Hex Version Hex Docs tests

Meeseeks is an Elixir library for parsing and extracting data from HTML and XML with CSS or XPath selectors.

import Meeseeks.CSS

html = HTTPoison.get!("https://news.ycombinator.com/").body

for story <- Meeseeks.all(html, css("tr.athing")) do
  title = Meeseeks.one(story, css(".title a"))

  %{
    title: Meeseeks.text(title),
    url: Meeseeks.attr(title, "href")
  }
end
#=> [%{title: "...", url: "..."}, %{title: "...", url: "..."}, ...]

Features

  • Friendly API
  • Browser-grade HTML5 parser
  • Permissive XML parser
  • CSS and XPath selectors
  • Supports custom selectors
  • Helpers to extract data from selections

Compatibility

Meeseeks requires a minimum combination of Elixir 1.7.0 and Erlang/OTP 21, and has been tested with a maximum combination of Elixir 1.11.0 and Erlang/OTP 23.0.

Installation

Meeseeks depends on html5ever via meeseeks_html5ever.

Because html5ever is a Rust library, you will need to have the Rust compiler installed wherever Meeseeks is compiled.

Ensure Rust is installed, then add Meeseeks to your mix.exs:

defp deps do
  [
    {:meeseeks, "~> 0.15.1"}
  ]
end

Finally, run mix deps.get.

Getting Started

Parse

Start by parsing a source (HTML/XML string or Meeseeks.TupleTree) into a Meeseeks.Document so that it can be queried.

Meeseeks.parse/1 parses the source as HTML, but Meeseeks.parse/2 accepts a second argument of either :html, :xml, or :tuple_tree that specifies how the source is parsed.

document = Meeseeks.parse("<div id=main><p>1</p><p>2</p><p>3</p></div>")
#=> #Meeseeks.Document<{...}>

The selection functions accept an unparsed source, parsing it as HTML, but parsing is expensive so parse ahead of time when running multiple selections on the same document.

Select

Next, use one of Meeseeks's selection functions - fetch_all, all, fetch_one, or one - to search for nodes.

All these functions accept a queryable (a source, a document, or a Meeseeks.Result), one or more Meeseeks.Selectors, and optionally an initial context.

all returns a (possibly empty) list of results representing every node matching one of the provided selectors, while one returns a result representing the first node to match a selector (depth-first) or nil if there is no match.

fetch_all and fetch_one work like all and one respectively, but wrap the result in {:ok, ...} if there is a match or return {:error, %Meeseeks.Error{type: :select, reason: :no_match}} if there is not.

To generate selectors, use the css macro provided by Meeseeks.CSS or the xpath macro provided by Meeseeks.XPath.

import Meeseeks.CSS
result = Meeseeks.one(document, css("#main p"))
#=> #Meeseeks.Result<{ <p>1</p> }>

import Meeseeks.XPath
result = Meeseeks.one(document, xpath("//*[@id='main']//p"))
#=> #Meeseeks.Result<{ <p>1</p> }>

Extract

Retrieve information from the Meeseeks.Result with an extractor.

The included extractors are attr, attrs, data, dataset, html, own_text, tag, text, tree.

Meeseeks.tag(result)
#=> "p"
Meeseeks.text(result)
#=> "1"
Meeseeks.tree(result)
#=> {"p", [], ["1"]}

The extractors html and tree work on Meeseeks.Documents in addition to Meeseeks.Results.

Meeseeks.html(document)
#=> "<html><head></head><body><div id=\"main\"><p>1</p><p>2</p><p>3</p></div></body></html>"

Guides

Contributing

If you are interested in contributing please read the contribution guidelines.

License

The MIT License (MIT)

Copyright (c) 2016-2020 Mischov (https://github.com/mischov)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].