{"id":31692441,"url":"https://github.com/hunlongyu/html_parser","last_synced_at":"2025-10-08T14:06:44.307Z","repository":{"id":317032082,"uuid":"1044792476","full_name":"Hunlongyu/html_parser","owner":"Hunlongyu","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-28T10:22:19.000Z","size":754,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-28T12:26:53.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Hunlongyu.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-26T08:08:10.000Z","updated_at":"2025-09-28T10:22:22.000Z","dependencies_parsed_at":"2025-09-28T17:32:47.059Z","dependency_job_id":null,"html_url":"https://github.com/Hunlongyu/html_parser","commit_stats":null,"previous_names":["hunlongyu/html_parser"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Hunlongyu/html_parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hunlongyu%2Fhtml_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hunlongyu%2Fhtml_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hunlongyu%2Fhtml_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hunlongyu%2Fhtml_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hunlongyu","download_url":"https://codeload.github.com/Hunlongyu/html_parser/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hunlongyu%2Fhtml_parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278956330,"owners_count":26075221,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-10-08T14:06:39.105Z","updated_at":"2025-10-08T14:06:44.292Z","avatar_url":"https://github.com/Hunlongyu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HPS HTML 解析库\n\n[![Version](https://img.shields.io/badge/version-0.0.2-blue.svg)](https://github.com/Hunlongyu/html_parser)\n[![C++](https://img.shields.io/badge/C++-23-blue.svg)](https://en.cppreference.com/w/cpp/23)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n\n\u003e ⚠️ **开发中 (WIP)** - 这是一个正在积极开发的项目，API 可能会发生变化。不建议在生产环境中使用当前版本。\n\n一个高性能、现代化的 C++ HTML 解析库，支持完整的 HTML5 标准解析和 CSS 选择器查询。\n\n## ✨ 核心特性\n\n### 🔍 强大的 CSS 选择器支持\n- **复杂选择器**：支持后代选择器、子选择器、相邻兄弟选择器、通用兄弟选择器\n- **属性选择器**：支持 `[attr]`、`[attr=value]`、`[attr^=value]`、`[attr$=value]`、`[attr*=value]` 等\n- **伪类选择器**：支持 `:first-child`、`:last-child`、`:nth-child()`、`:not()` 等\n- **组合选择器**：支持多重选择器组合和复杂嵌套查询\n\n### ⛓️ 流畅的链式查询 API\n- **链式调用**：`doc-\u003ecss(\".container\").find(\"h1\").has_class(\"title\").first_element()`\n- **过滤方法**：`has_class()`、`has_attribute()`、`containing_text()`、`matches()` 等\n- **导航方法**：`parent()`、`children()`、`siblings()`、`closest()`、`find()` 等\n- **结果处理**：`first_element()`、`last_element()`、`at(index)`、`filter()` 等\n\n### ⚙️ 灵活的解析配置项\n- **解析选项**：自定义解析行为，控制容错级别和处理策略\n- **片段解析**：支持 HTML 片段解析，无需完整文档结构\n- **错误处理**：可配置的错误恢复策略和警告级别\n\n### 📄 双层查询架构\n- **Document 查询**：从文档根节点开始的全局查询\n  ```cpp\n  auto results = doc-\u003ecss(\"div.container p\");\n  ```\n- **Element 查询**：从任意元素节点开始的局部查询\n  ```cpp\n  auto container = doc-\u003ecss(\".container\").first_element();\n  auto paragraphs = container-\u003ecss(\"p\");  // 仅在容器内查询\n  ```\n\n### 🚀 高性能解析引擎\n- **标准兼容**：完全遵循 HTML5 解析规范（Tokenizer → Tree Construction → DOM Tree）\n- **内存优化**：内存池管理、零拷贝设计、智能缓存机制\n- **查询加速**：ID/类名索引、LRU 策略优化\n- **现代 C++23**：模块化架构，充分利用新语言特性\n- **无第三方依赖**：仅依赖 C++23 标准库，无需额外安装任何第三方库\n\n## 🚀 快速演示\n\n### 基础查询示例\n```cpp\n#include \u003chps/hps.hpp\u003e\n#include \u003ciostream\u003e\n\nint main() {\n    std::string html = R\"(\n        \u003cdiv class=\"container\"\u003e\n            \u003cheader class=\"site-header\"\u003e\n                \u003ch1 id=\"title\" class=\"main-title\"\u003e网站标题\u003c/h1\u003e\n                \u003cnav class=\"navigation\"\u003e\n                    \u003cul class=\"nav-menu\"\u003e\n                        \u003cli class=\"nav-item active\"\u003e\u003ca href=\"#home\"\u003e首页\u003c/a\u003e\u003c/li\u003e\n                        \u003cli class=\"nav-item\"\u003e\u003ca href=\"#about\"\u003e关于\u003c/a\u003e\u003c/li\u003e\n                    \u003c/ul\u003e\n                \u003c/nav\u003e\n            \u003c/header\u003e\n            \u003cmain class=\"content\"\u003e\n                \u003carticle class=\"post\" data-id=\"123\"\u003e\n                    \u003ch2 class=\"post-title\"\u003e文章标题\u003c/h2\u003e\n                    \u003cp class=\"post-content\"\u003e文章内容...\u003c/p\u003e\n                \u003c/article\u003e\n            \u003c/main\u003e\n        \u003c/div\u003e\n    )\";\n    \n    // 解析配置\n    hps::Options options;\n    options.encoding = \"UTF-8\";\n    options.fragment_parsing = true;\n    \n    auto doc = hps::parse(html, options);\n    \n    // 复杂 CSS 选择器查询\n    auto activeNav = doc-\u003ecss(\".navigation .nav-item.active a\").first_element();\n    std::cout \u003c\u003c \"活跃导航: \" \u003c\u003c activeNav-\u003etext_content() \u003c\u003c std::endl;\n    \n    // 属性选择器\n    auto article = doc-\u003ecss(\"article[data-id='123']\").first_element();\n    std::cout \u003c\u003c \"文章ID: \" \u003c\u003c article-\u003eget_attribute(\"data-id\") \u003c\u003c std::endl;\n    \n    return 0;\n}\n```\n\n### 链式查询示例\n```cpp\n#include \u003chps/hps.hpp\u003e\n\nint main() {\n    std::string html = R\"(\n        \u003cdiv class=\"products\"\u003e\n            \u003cdiv class=\"product featured\" data-price=\"199\"\u003e\n                \u003ch3 class=\"name\"\u003e产品A\u003c/h3\u003e\n                \u003cspan class=\"price\"\u003e¥199\u003c/span\u003e\n                \u003cdiv class=\"tags\"\u003e\n                    \u003cspan class=\"tag new\"\u003e新品\u003c/span\u003e\n                    \u003cspan class=\"tag sale\"\u003e促销\u003c/span\u003e\n                \u003c/div\u003e\n            \u003c/div\u003e\n            \u003cdiv class=\"product\" data-price=\"299\"\u003e\n                \u003ch3 class=\"name\"\u003e产品B\u003c/h3\u003e\n                \u003cspan class=\"price\"\u003e¥299\u003c/span\u003e\n            \u003c/div\u003e\n        \u003c/div\u003e\n    )\";\n    \n    auto doc = hps::parse(html);\n    \n    // 链式查询：查找推荐产品中的促销商品\n    auto featuredSaleProducts = doc-\u003ecss(\".product\")\n                                  .has_class(\"featured\")\n                                  .find(\".tag\")\n                                  .containing_text(\"促销\")\n                                  .closest(\".product\");\n    \n    for (const auto\u0026 product : featuredSaleProducts) {\n        auto name = product-\u003ecss(\".name\").first_element()-\u003etext_content();\n        auto price = product-\u003eget_attribute(\"data-price\");\n        std::cout \u003c\u003c \"推荐促销产品: \" \u003c\u003c name \u003c\u003c \", 价格: ¥\" \u003c\u003c price \u003c\u003c std::endl;\n    }\n    \n    // Element 级别查询\n    auto productsContainer = doc-\u003ecss(\".products\").first_element();\n    auto cheapProducts = productsContainer-\u003ecss(\".product\")\n                           .filter([](const auto\u0026 elem) {\n                               auto price = std::stoi(elem-\u003eget_attribute(\"data-price\"));\n                               return price \u003c 250;\n                           });\n    \n    std::cout \u003c\u003c \"找到 \" \u003c\u003c cheapProducts.size() \u003c\u003c \" 个便宜产品\" \u003c\u003c std::endl;\n    \n    return 0;\n}\n```\n\n## 📦 快速安装\n\n### 系统要求\n- C++23 兼容编译器（MSVC 2022+）\n- CMake 3.28+\n\n### 构建步骤\n```bash\ngit clone https://github.com/Hunlongyu/html_parser.git\ncd html_parser\nmkdir build \u0026\u0026 cd build\ncmake ..\ncmake --build . --config Release\n```\n\n### CMake 集成\n```cmake\nadd_subdirectory(path/to/hps)\ntarget_link_libraries(your_target hps_static)\n```\n\n## 📚 文档链接\n\n- [📖 详细 API 文档](docs/API.md)\n- [🔧 详细构建说明](docs/BUILD.md)\n- [💡 完整示例代码](examples/)\n- [🏗️ 设计文档](docs/HPS%20HTML%20解析库详细设计文档.md)\n\n## 📋 TODO\n\n- [ ] **XPath 支持**：完整的 XPath 1.0 表达式支持（开发中）\n- [ ] 性能基准测试\n\n## 🤝 贡献\n\n欢迎提交 Issue 和 Pull Request！\n\n- 🐛 发现 Bug？[提交 Issue](https://github.com/Hunlongyu/html_parser/issues)\n- 💡 有新想法？[讨论功能请求](https://github.com/Hunlongyu/html_parser/discussions)\n- 🔧 想要贡献代码？查看 [贡献指南](CONTRIBUTING.md)\n\n## 📄 许可证\n本项目采用 [MIT 许可证](LICENSE)。\n\n---\n\n⭐ 如果这个项目对您有帮助，请给我们一个 Star！","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunlongyu%2Fhtml_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhunlongyu%2Fhtml_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhunlongyu%2Fhtml_parser/lists"}