https://github.com/calvinmclean/html_parser
  
  
    a simple HTML parser using Gleam 
    https://github.com/calvinmclean/html_parser
  
        Last synced: 4 months ago 
        JSON representation
    
a simple HTML parser using Gleam
- Host: GitHub
- URL: https://github.com/calvinmclean/html_parser
- Owner: calvinmclean
- Created: 2024-08-10T05:37:59.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-27T22:51:27.000Z (11 months ago)
- Last Synced: 2025-03-02T05:30:09.448Z (8 months ago)
- Language: HTML
- Size: 37.1 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
 
Awesome Lists containing this project
README
          # html_parser
[](https://hex.pm/packages/html_parser)
[](https://hexdocs.pm/html_parser/)
`html_parser` is a simple library for parsing an HTML document. Use `html_parser.as_list` to parse the document
as List of Elements. Use `html_parser.as_tree` to create a nested structure where Elements have children.
- `StartElement`: HTML opening tag, like `
`
- `EndElement`: HTML closing tag, like ``
- `Content`: Non-HTML parts of the document inside tags (the "hello" in `hello`)
- `Attributes`: HTML attributes inside of a tag (`href` key and value in ``)
```sh
gleam add html_parser@1
```
```gleam
import html_parser
pub fn main() {
  "
Data!"
  |> html_parser.as_list
  |> find_div
  |> io.debug
}
// find a starting div where class=data and the next element is Content
fn find_div(in: List(html_parser.Element)) -> String {
  case in {
    [] -> "Not found"
    [
      html_parser.StartElement("div", [html_parser.Attribute("class", "data")], _),
      html_parser.Content(contents),
      ..
    ] -> contents
    [_, ..tail] -> find_div(tail)
  }
}
```
Further documentation can be found at .
## Development
```sh
gleam run   # Run the project
gleam test  # Run the tests
```