{"id":25802276,"url":"https://github.com/ikenox/h2s-rs","last_synced_at":"2026-03-14T13:47:10.302Z","repository":{"id":37047911,"uuid":"488658521","full_name":"ikenox/h2s-rs","owner":"ikenox","description":"A declarative and ergonomic HTML parser library in Rust","archived":false,"fork":false,"pushed_at":"2023-08-16T12:50:57.000Z","size":246,"stargazers_count":4,"open_issues_count":9,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T04:48:21.036Z","etag":null,"topics":["html","parser","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ikenox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-04T16:13:03.000Z","updated_at":"2024-10-26T02:05:35.000Z","dependencies_parsed_at":"2023-01-25T22:16:06.145Z","dependency_job_id":null,"html_url":"https://github.com/ikenox/h2s-rs","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikenox%2Fh2s-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikenox%2Fh2s-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikenox%2Fh2s-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikenox%2Fh2s-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikenox","download_url":"https://codeload.github.com/ikenox/h2s-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241037253,"owners_count":19898301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","parser","rust"],"created_at":"2025-02-27T16:57:47.903Z","updated_at":"2026-03-14T13:47:05.269Z","avatar_url":"https://github.com/ikenox.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Check](https://github.com/ikenox/h2s/actions/workflows/check.yml/badge.svg?branch=main)](https://github.com/ikenox/h2s/actions/workflows/check.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![Rustc Version 1.65+](https://img.shields.io/badge/rustc-1.65+-bc71d0.svg)\n\n# h2s\n\n\u003c!-- cargo-rdme start --\u003e\n\nA declarative HTML parser library in Rust, which works like a deserializer from HTML to struct.\n\n## Example\n\n```rust\nuse h2s::FromHtml;\nuse h2s::extraction_method::ExtractNthText;\n\n#[derive(FromHtml, Debug, Eq, PartialEq)]\npub struct Page {\n    #[h2s(attr = \"lang\")]\n    lang: String,\n    #[h2s(select = \"div \u003e h1.blog-title\")]\n    blog_title: String,\n    #[h2s(select = \".articles \u003e div\")]\n    articles: Vec\u003cArticle\u003e,\n    #[h2s(select = \"body\", extractor = ExtractNthText(1))]\n    footer2: String,\n}\n\n#[derive(FromHtml, Debug, Eq, PartialEq)]\npub struct Article {\n    #[h2s(select = \"h2 \u003e a\")]\n    title: String,\n    #[h2s(select = \"div \u003e span\")]\n    view_count: usize,\n    #[h2s(select = \"h2 \u003e a\", attr = \"href\")]\n    url: String,\n    #[h2s(select = \"ul \u003e li\")]\n    tags: Vec\u003cString\u003e,\n    #[h2s(select = \"ul \u003e li:nth-child(1)\")]\n    first_tag: Option\u003cString\u003e,\n}\n\nlet html = r#\"\n\u003chtml lang=\"en\"\u003e\n\u003cbody\u003e\n  \u003cdiv\u003e\n      \u003ch1 class=\"blog-title\"\u003eMy tech blog\u003c/h1\u003e\n      \u003cdiv class=\"articles\"\u003e\n          \u003cdiv\u003e\n              \u003ch2\u003e\u003ca href=\"https://example.com/1\"\u003earticle1\u003c/a\u003e\u003c/h2\u003e\n              \u003cdiv\u003e\u003cspan\u003e901\u003c/span\u003e Views\u003c/div\u003e\n              \u003cul\u003e\u003cli\u003eTag1\u003c/li\u003e\u003cli\u003eTag2\u003c/li\u003e\u003c/ul\u003e\n          \u003c/div\u003e\n          \u003cdiv\u003e\n              \u003ch2\u003e\u003ca href=\"https://example.com/2\"\u003earticle2\u003c/a\u003e\u003c/h2\u003e\n              \u003cdiv\u003e\u003cspan\u003e849\u003c/span\u003e Views\u003c/div\u003e\n              \u003cul\u003e\u003c/ul\u003e\n          \u003c/div\u003e\n          \u003cdiv\u003e\n              \u003ch2\u003e\u003ca href=\"https://example.com/3\"\u003earticle3\u003c/a\u003e\u003c/h2\u003e\n              \u003cdiv\u003e\u003cspan\u003e103\u003c/span\u003e Views\u003c/div\u003e\n              \u003cul\u003e\u003cli\u003eTag3\u003c/li\u003e\u003c/ul\u003e\n          \u003c/div\u003e\n      \u003c/div\u003e\n  \u003c/div\u003e\n  footer1\n  \u003chr /\u003e\n  footer2\n\u003c/body\u003e\n\u003c/html\u003e\n\"#;\n\nlet page = h2s::parse::\u003cPage\u003e(html).unwrap();\n\nassert_eq!(page, Page {\n    lang: \"en\".to_string(),\n    blog_title: \"My tech blog\".to_string(),\n    articles: vec![\n        Article {\n            title: \"article1\".to_string(),\n            url: \"https://example.com/1\".to_string(),\n            view_count: 901,\n            tags: vec![\"Tag1\".to_string(), \"Tag2\".to_string()],\n            first_tag: Some(\"Tag1\".to_string()),\n        },\n        Article {\n            title: \"article2\".to_string(),\n            url: \"https://example.com/2\".to_string(),\n            view_count: 849,\n            tags: vec![],\n            first_tag: None,\n        },\n        Article {\n            title: \"article3\".to_string(),\n            url: \"https://example.com/3\".to_string(),\n            view_count: 103,\n            tags: vec![\"Tag3\".to_string()],\n            first_tag: Some(\"Tag3\".to_string()),\n        },\n    ],\n    footer2: \"footer2\".to_string(),\n});\n\n// When the input HTML document structure does not match the expected,\n// `h2s::parse` will return an error with a detailed reason.\nlet invalid_html = html.replace(r#\"\u003ca href=\"https://example.com/3\"\u003earticle3\u003c/a\u003e\"#, \"\");\nlet err = h2s::parse::\u003cPage\u003e(invalid_html).unwrap_err();\nassert_eq!(\n  err.to_string(),\n  \"articles: [2]: title: mismatched number of selected elements by \\\"h2 \u003e a\\\": expected exactly one element, but no elements found\"\n);\n```\n\n## Supported types\n\nYou can use the following types as a field value of the struct to parse.\n\n### Basic types\n\n  - `String`\n  - Numeric types ( `usize`, `i64`, `NonZeroU32`, ... )\n  - And more built-in supported types ([List](./core/src/parseable.rs))\n  - Or you can use any types by implementing yourself ([Example](./examples/custom_field_value.rs))\n\n### Container types (where `T` is a basic type)\n\n  - `[T;N]`\n  - `Option\u003cT\u003e`\n  - `Vec\u003cT\u003e`\n\n\u003c!-- cargo-rdme end --\u003e\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikenox%2Fh2s-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikenox%2Fh2s-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikenox%2Fh2s-rs/lists"}