Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maiha/hq.cr
a simple wrapper for crystal-xml
https://github.com/maiha/hq.cr
Last synced: 4 days ago
JSON representation
a simple wrapper for crystal-xml
- Host: GitHub
- URL: https://github.com/maiha/hq.cr
- Owner: maiha
- License: mit
- Created: 2016-11-13T17:19:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-11-29T01:39:05.000Z (almost 3 years ago)
- Last Synced: 2024-08-01T17:35:34.196Z (3 months ago)
- Language: Crystal
- Size: 13.7 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - hq.cr - Simple wrapper for crystal-xml (HTML/XML Parsing)
- awesome-crystal - hq.cr - Simple wrapper for crystal-xml (HTML/XML Parsing)
README
## WARNING: This library is no longer maintained because something wonderful has come along. Try to enjoy: [Lexbor](https://github.com/kostya/lexbor).
# hq.cr [![Build Status](https://travis-ci.org/maiha/hq.cr.svg?branch=master)](https://travis-ci.org/maiha/hq.cr)
a simple wrapper for crystal-xml and myhtml
- gateway pattern : suppress errors until values are referenced
- handy accessors : provide useful extractors and conversions## Installation
- crystal: 0.23.x
Add this to your application's `shard.yml`:
```yaml
dependencies:
hq:
github: maiha/hq.cr
version: 0.2.3
```## xpath
```crystal
require "hq"node = Hq.parse("
82 users")
node.xpath("/html/body/div").text # => "82 users"
node.xpath("/html/body/div").int # => 82
node.xpath("/html/body/nav").int? # => nil
node.xpath("/html/body").path # => "/html/body"
node.xpath("/html/div").text # raise Hq::NotFound.new(key: "/html/div")
```## css
- css selector
```crystal
nodes = Hq::Css.parse <<-EOF
- foo
- bar
EOF
nodes.css("li").map(&.text) # => ["foo", "bar"]
```
- node attributes
```crystal
nodes = Hq::Css.parse <<-EOF
crystal
hq.cr
EOF
nodes.css("a").each do |a|
p [a["href"], a["class"]?]
end
# => ["https://github.com/crystal-lang/crystal", "official"]
# => ["https://github.com/maiha/hq.cr", nil]
```
## Roadmap
#### 0.2.0
- [x] support `css(tag)`
#### 0.3.0
- [ ] support `css(tag_with_class)`
- [x] support `Css::Node#attributes`
#### 0.4.0
- [ ] support `Hq.mapping` like `jq.cr`
## Contributing
1. Fork it ( https://github.com/maiha/hq.cr/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
## Contributors
- [maiha](https://github.com/maiha) maiha - creator, maintainer