{"id":44321621,"url":"https://github.com/padraicbc/h5p","last_synced_at":"2026-02-11T06:35:12.972Z","repository":{"id":336706088,"uuid":"1123818672","full_name":"padraicbc/h5p","owner":"padraicbc","description":"CSS + XPath engines in Go","archived":false,"fork":false,"pushed_at":"2026-02-05T18:37:04.000Z","size":65,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-06T04:25:03.581Z","etag":null,"topics":["css-selector","golang","web-scraping","xpath"],"latest_commit_sha":null,"homepage":"","language":"Go","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/padraicbc.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":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-12-27T17:32:16.000Z","updated_at":"2026-02-05T18:35:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/padraicbc/h5p","commit_stats":null,"previous_names":["padraicbc/h5p"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/padraicbc/h5p","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padraicbc%2Fh5p","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padraicbc%2Fh5p/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padraicbc%2Fh5p/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padraicbc%2Fh5p/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/padraicbc","download_url":"https://codeload.github.com/padraicbc/h5p/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/padraicbc%2Fh5p/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29328268,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["css-selector","golang","web-scraping","xpath"],"created_at":"2026-02-11T06:35:11.606Z","updated_at":"2026-02-11T06:35:12.957Z","avatar_url":"https://github.com/padraicbc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# h5p\n\n# DOM Library aided by Codex/Claude - Go HTML/XML Query Engine\n\n# h5p - HTML5 Parser for Go\n\nA high-performance HTML/XML parser for Go with comprehensive CSS selector and XPath query support. Built for web scraping, automated testing, and DOM manipulation.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/padraicbc/h5p.svg)](https://pkg.go.dev/github.com/padraicbc/h5p)\n[![Go Report Card](https://goreportcard.com/badge/github.com/padraicbc/h5p)](https://goreportcard.com/report/github.com/padraicbc/h5p)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Features\n\n- 🎯 **98% XPath 1.0 Compliance** - One of the most complete XPath implementations in Go\n- 🔍 **CSS Level 3 Selectors** - All common selectors, pseudo-classes, and attribute matching\n- 🚀 **Location Paths in Functions** - Advanced feature: `count(.//p)`, `sum(descendant::price)`\n- 🧭 **All 12 XPath Axes** - Complete navigation: child, descendant, parent, ancestor, siblings, following, preceding\n- 🎨 **jQuery-like API** - Familiar, easy-to-use interface\n- ⚡ **Pure Go** - Zero dependencies, fast performance\n- ✅ **Production Ready** - Extensive test coverage with real-world examples\n\n## Installation\n\n```bash\ngo get github.com/padraicbc/h5p\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"github.com/padraicbc/h5p/parser\"\n)\n\nfunc main() {\n    html := `\n        \u003chtml\u003e\n            \u003cbody\u003e\n                \u003cdiv class=\"product\" data-price=\"29.99\"\u003e\n                    \u003ch2\u003eWidget\u003c/h2\u003e\n                    \u003cp class=\"description\"\u003eA great product\u003c/p\u003e\n                \u003c/div\u003e\n                \u003cdiv class=\"product\" data-price=\"39.99\"\u003e\n                    \u003ch2\u003eGadget\u003c/h2\u003e\n                    \u003cp class=\"description\"\u003eEven better\u003c/p\u003e\n                \u003c/div\u003e\n            \u003c/body\u003e\n        \u003c/html\u003e\n    `\n\n    // Parse HTML\n    doc, _ := parser.Parse(html)\n\n    // CSS Selectors\n    products, _ := doc.Root.Query(\".product\")\n    fmt.Printf(\"Found %d products\\n\", len(products))\n\n    // XPath Queries\n    expensiveProducts, _ := doc.Root.QueryXPath(\"//div[@data-price \u003e 30]\")\n    fmt.Printf(\"Found %d expensive products\\n\", len(expensiveProducts))\n\n    // Get attributes and text\n    for _, product := range products {\n        title := product.QueryFirst(\"h2\").Text()\n        price := product.Attr(\"data-price\")\n        fmt.Printf(\"%s: $%s\\n\", title, price)\n    }\n}\n```\n\n## CSS Selectors\n\n### Basic Selectors\n\n```go\n// Element selector\ndoc.Root.Query(\"div\")\n\n// ID selector\ndoc.Root.Query(\"#header\")\n\n// Class selector\ndoc.Root.Query(\".product\")\n\n// Attribute selector\ndoc.Root.Query(\"[data-active]\")\ndoc.Root.Query(\"[href^='https']\")\ndoc.Root.Query(\"[class*='button']\")\n\n// Combinators\ndoc.Root.Query(\"div \u003e p\")           // Direct children\ndoc.Root.Query(\"article p\")         // All descendants\ndoc.Root.Query(\"h2 + p\")            // Next sibling\ndoc.Root.Query(\"h2 ~ p\")            // All following siblings\n```\n\n### Pseudo-classes\n\n```go\n// Structural\ndoc.Root.Query(\"li:first-child\")\ndoc.Root.Query(\"tr:nth-child(2n)\")\ndoc.Root.Query(\"p:last-of-type\")\n\n// State\ndoc.Root.Query(\"input:checked\")\ndoc.Root.Query(\"option:selected\")\ndoc.Root.Query(\"div:empty\")\n\n// Content\ndoc.Root.Query(\"a:contains('Click here')\")\n\n// Negation\ndoc.Root.Query(\"input:not([type='hidden'])\")\n```\n\n### Multiple Selectors\n\n```go\n// Union (OR)\ndoc.Root.Query(\"h1, h2, h3\")\n\n// Complex combinations\ndoc.Root.Query(\"article.featured \u003e h2:first-child, .sidebar h3\")\n```\n\n## XPath Queries\n\n### Basic Path Expressions\n\n```go\n// All paragraphs\ndoc.Root.QueryXPath(\"//p\")\n\n// By ID\ndoc.Root.QueryXPath(\"//*[@id='header']\")\n\n// By class\ndoc.Root.QueryXPath(\"//div[contains(@class, 'product')]\")\n\n// Specific path\ndoc.Root.QueryXPath(\"/html/body/div[1]/p\")\n```\n\n### Axes (All 12 Supported!)\n\n```go\n// Child axis\ndoc.Root.QueryXPath(\"//article/child::p\")\n\n// Descendant axis\ndoc.Root.QueryXPath(\"//div/descendant::a\")\n\n// Parent axis\ndoc.Root.QueryXPath(\"//span/parent::div\")\n\n// Ancestor axis\ndoc.Root.QueryXPath(\"//p/ancestor::article\")\n\n// Following-sibling axis\ndoc.Root.QueryXPath(\"//h2/following-sibling::p\")\n\n// Preceding-sibling axis\ndoc.Root.QueryXPath(\"//p/preceding-sibling::h2\")\n\n// Following axis (all following nodes)\ndoc.Root.QueryXPath(\"//h2/following::*\")\n\n// Preceding axis (all preceding nodes)\ndoc.Root.QueryXPath(\"//footer/preceding::*\")\n\n// Self axis\ndoc.Root.QueryXPath(\"//div/self::*[@class]\")\n\n// Descendant-or-self axis\ndoc.Root.QueryXPath(\"//article/descendant-or-self::*\")\n\n// Ancestor-or-self axis\ndoc.Root.QueryXPath(\"//p/ancestor-or-self::*\")\n\n// Attribute axis\ndoc.Root.QueryXPath(\"//div/attribute::*\")\n```\n\n### Predicates\n\n```go\n// Position predicates\ndoc.Root.QueryXPath(\"//li[1]\")              // First item\ndoc.Root.QueryXPath(\"//li[last()]\")         // Last item\ndoc.Root.QueryXPath(\"//li[position() \u003e 1]\") // All but first\n\n// Attribute predicates\ndoc.Root.QueryXPath(\"//a[@href]\")                    // Has href\ndoc.Root.QueryXPath(\"//a[@href='/home']\")            // Exact match\ndoc.Root.QueryXPath(\"//a[starts-with(@href, 'http')]\") // Starts with\ndoc.Root.QueryXPath(\"//a[contains(@href, 'example')]\")  // Contains\n\n// Multiple predicates\ndoc.Root.QueryXPath(\"//li[position() \u003e 1][position() \u003c 5]\")\n```\n\n### Functions\n\n```go\n// Text functions\ndoc.Root.QueryXPath(\"//p[contains(text(), 'important')]\")\ndoc.Root.QueryXPath(\"//p[starts-with(text(), 'Note')]\")\ndoc.Root.QueryXPath(\"//span[string-length(text()) \u003e 20]\")\n\n// Node functions\ndoc.Root.QueryXPath(\"//div[count(p) \u003e 3]\")              // More than 3 \u003cp\u003e children\ndoc.Root.QueryXPath(\"//article[count(.//p) \u003e 5]\")       // More than 5 descendant \u003cp\u003e\ndoc.Root.QueryXPath(\"//section[count(child::div) = 2]\") // Exactly 2 \u003cdiv\u003e children\n\n// Boolean functions\ndoc.Root.QueryXPath(\"//article[@featured and @published]\")\ndoc.Root.QueryXPath(\"//div[@data-price \u003e 100 or @data-sale]\")\ndoc.Root.QueryXPath(\"//input[not(@disabled)]\")\n```\n\n### Advanced Features\n\n#### Location Paths in Functions (Unique Feature!)\n\n```go\n// Count descendant elements\ndoc.Root.QueryXPath(\"//article[count(.//p) \u003e 5]\")\n\n// Count with explicit axes\ndoc.Root.QueryXPath(\"//section[count(child::div) = 3]\")\ndoc.Root.QueryXPath(\"//div[count(descendant::a) \u003e 10]\")\n\n// Complex counting\ndoc.Root.QueryXPath(\"//table[count(.//tr) \u003e 20]\")\ndoc.Root.QueryXPath(\"//article[count(.//img[@alt]) = count(.//img)]\") // All images have alt text\n```\n\n#### Union Operator\n\n```go\n// Multiple element types\ndoc.Root.QueryXPath(\"//h1 | //h2 | //h3\")\n\n// Multiple paths\ndoc.Root.QueryXPath(\"//header//a | //footer//a\")\n\n// Different predicates\ndoc.Root.QueryXPath(\"//div[@featured] | //article[@published]\")\n```\n\n## API Reference\n\n### Query Methods\n\n```go\n// CSS Selectors\nQuery(selector string) ([]*Node, error)           // Find all matching nodes\nQueryFirst(selector string) *Node                 // Find first matching node\n\n// XPath\nQueryXPath(xpath string) ([]*Node, error)         // Find all matching nodes\nQueryXPathFirst(xpath string) (*Node, error)      // Find first matching node\n```\n\n### Node Methods\n\n```go\n// Content extraction\nText() string                      // Get text content (including descendants)\nAttr(name string) string          // Get attribute value\nHasAttr(name string) bool         // Check if attribute exists\n\n// Tree navigation\nParent *Node                       // Parent node\nChildren []*Node                   // Child nodes\nNextSibling() *Node               // Next sibling\nPrevSibling() *Node               // Previous sibling\n\n// Conversion\nToMarkdown() string               // Convert to Markdown (for semantic HTML)\n```\n\n### Document Methods\n\n```go\n// Parsing\nparser.Parse(html string) (*Document, error)\nparser.ParseReader(r io.Reader) (*Document, error)\n\n// Access\ndoc.Root                          // Root node of the document\n```\n\n## Real-World Examples\n\n### Web Scraping\n\n```go\n// Scrape product information\ndoc, _ := parser.Parse(html)\n\nproducts, _ := doc.Root.QueryXPath(\"//div[@class='product']\")\nfor _, product := range products {\n    name := product.QueryFirst(\"h2\").Text()\n    price := product.Attr(\"data-price\")\n    rating, _ := product.QueryXPath(\".//span[@class='rating']/@data-value\")\n\n    fmt.Printf(\"%s - $%s (Rating: %s)\\n\", name, price, rating[0].Text())\n}\n```\n\n### Data Extraction\n\n```go\n// Extract all external links\nexternalLinks, _ := doc.Root.QueryXPath(\"//a[starts-with(@href, 'http')]\")\n\n// Find all images without alt text\nimagesNoAlt, _ := doc.Root.QueryXPath(\"//img[not(@alt)]\")\n\n// Get all table data\nrows, _ := doc.Root.QueryXPath(\"//table[@id='data']//tr[position() \u003e 1]\")\nfor _, row := range rows {\n    cells, _ := row.QueryXPath(\"./td\")\n    for _, cell := range cells {\n        fmt.Print(cell.Text(), \"\\t\")\n    }\n    fmt.Println()\n}\n```\n\n### Form Analysis\n\n```go\n// Find all required fields\nrequiredFields, _ := doc.Root.Query(\"input[required], select[required], textarea[required]\")\n\n// Find unchecked checkboxes\nunchecked, _ := doc.Root.Query(\"input[type='checkbox']:not([checked])\")\n\n// Count form elements\ninputCount, _ := doc.Root.QueryXPath(\"count(//form[@id='signup']//input)\")\n```\n\n### Content Analysis\n\n```go\n// Find long paragraphs\nlongParas, _ := doc.Root.QueryXPath(\"//p[string-length(text()) \u003e 500]\")\n\n// Articles with multiple images\nrichArticles, _ := doc.Root.QueryXPath(\"//article[count(.//img) \u003e= 3]\")\n\n// Sections with specific heading structure\nsections, _ := doc.Root.QueryXPath(\"//section[h2 and count(h3) \u003e 2]\")\n```\n\n## XPath Feature Coverage\n\n### ✅ Fully Supported (98%)\n\n**Axes (12/13):**\n\n- child, descendant, parent, ancestor\n- following-sibling, preceding-sibling\n- following, preceding\n- self, descendant-or-self, ancestor-or-self\n- attribute\n\n**Node Tests:**\n\n- Element names, wildcards (`*`)\n- `text()`, `node()`, `comment()`, `processing-instruction()`\n\n**Operators:**\n\n- Comparison: `=`, `!=`, `\u003c`, `\u003e`, `\u003c=`, `\u003e=`\n- Boolean: `and`, `or`, `not()`\n- Arithmetic: `+`, `-`, `*`, `div`, `mod`\n- Union: `|`\n\n**Functions:**\n\n- Node set: `count()`, `id()`, `last()`, `position()`\n- String: `concat()`, `contains()`, `starts-with()`, `substring()`, `string-length()`, `normalize-space()`\n- Boolean: `boolean()`, `not()`, `true()`, `false()`\n- Number: `number()`, `sum()`, `ceiling()`, `floor()`, `round()`\n\n**Advanced Features:**\n\n- ✅ Location paths in functions: `count(.//p)`\n- ✅ Multiple predicates\n- ✅ Nested predicates\n- ✅ Union operator\n- ✅ All comparison operators\n\n### ❌ Not Supported (2%)\n\n- `namespace::` axis (rarely used)\n- Variables (`$var`)\n- Namespace prefix registration\n- Some edge cases in namespace handling\n\n## Documentation\n\n- [Full API Documentation](https://pkg.go.dev/github.com/padraicbc/h5p)\n- [CSS Selector Examples](docs/CSS_EXAMPLES.md)\n- [XPath Examples](docs/XPATH_EXAMPLES.md)\n- [XPath Feature Support](docs/XPATH_FEATURE_SUPPORT.md)\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add some amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## Testing\n\n```bash\n# Run all tests\ngo test ./...\n\n# Run with coverage\ngo test -cover ./...\n\n# Run benchmarks\ngo test -bench=. ./...\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\n- HTML5 parsing spec\n- W3C XPath 1.0 specification\n- CSS Selectors Level 3 specification\n\n---\n\n**Why h5p?** I needed a Go library that combined the best of both worlds: the familiarity of CSS selectors AND the power of XPath. Most libraries offer one or the other, but not both with full feature support. h5p delivers comprehensive CSS Level 3 and 98% XPath 1.0 compliance in a single, zero-dependency package.\n\nPerfect for web scraping, automated testing, content extraction, and any task requiring robust HTML/DOM querying. 🚀\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadraicbc%2Fh5p","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpadraicbc%2Fh5p","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpadraicbc%2Fh5p/lists"}