Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calsranna/html_parser_plus
Use custom rule to parse html document
https://github.com/calsranna/html_parser_plus
Last synced: about 1 month ago
JSON representation
Use custom rule to parse html document
- Host: GitHub
- URL: https://github.com/calsranna/html_parser_plus
- Owner: CalsRanna
- License: mit
- Created: 2022-10-20T07:14:36.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-10T20:16:35.000Z (about 1 year ago)
- Last Synced: 2024-09-29T09:04:14.882Z (4 months ago)
- Language: Dart
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Html Parser
This is a package use to parse html document into nodes and string.
## Install
```bash
flutter pub add html_parser_plus
```## Getting started
```dart
import 'package:html_parser_plus/html_parser_plus.dart';void main() {
const String htmlString = '''
div head
1
2
3
4one
two
three
four
end
''';
final parser = HtmlParser();
var node = parser.parse(htmlString);
parser.query(node, '//div/a@text');
parser.query(
node,
'//div/a/@href|dart.replace(https://,)|dart.substring(0,10)',
);
parser.queryNodes(node, '//tr/td|dart.sublist(0,2)');const String jsonString = '''
{"author":"Cals Ranna","website":"https://github.com/CalsRanna","books":[{"name":"Hello"},{"name":"World"},{"name":"!"}]}
''';node = parser.parse(jsonString);
parser.query(node, r'$.author');
parser.query(
node,
r'$.website|dart.replace(https://,)|dart.substring(0,10)',
);
parser.queryNodes(node, r'$.books|dart.sublist(0,2)');
}```
## Usage
So far, we have supported:
- some **xpath** syntax by **xpath_selector**
- almost all **jsonPath** syntax by **json_path**And seven supported functions list below:
- **sublist** for `List`
- **replace** for `String`
- **replaceFirst** for `String`
- **replaceRegExp** for `String`
- **substring** for `String`
- **trim** for `String`
- **interpolate** for `String`, use `{{string}}` to indicate the piped value
- **match** for `String`> You should know that in the function, the params **CAN NOT** be wrapped by **'** or **"**.
> And the rule is like **//div/a@text|dart.replace(Author,)|dart.replace( ,)|dart.interpolate(作者:{{string}})**.
> Use **|** to pipe all rules.
## Legacy
- `function:` will be replaced by `dart.` in the future.