{"id":13764116,"url":"https://github.com/antchfx/xquery","last_synced_at":"2025-05-10T17:31:40.298Z","repository":{"id":57479489,"uuid":"70380227","full_name":"antchfx/xquery","owner":"antchfx","description":"Extract data or evaluate value from HTML/XML documents using XPath","archived":true,"fork":false,"pushed_at":"2018-05-15T05:19:11.000Z","size":96,"stargazers_count":158,"open_issues_count":0,"forks_count":27,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-11-16T23:32:37.571Z","etag":null,"topics":["extracting","golang","html","scraping","xml","xpath"],"latest_commit_sha":null,"homepage":"https://github.com/antchfx/xpath","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/antchfx.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":"2016-10-09T05:54:10.000Z","updated_at":"2024-10-01T23:39:57.000Z","dependencies_parsed_at":"2022-09-13T03:11:10.882Z","dependency_job_id":null,"html_url":"https://github.com/antchfx/xquery","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antchfx%2Fxquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antchfx%2Fxquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antchfx%2Fxquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antchfx%2Fxquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antchfx","download_url":"https://codeload.github.com/antchfx/xquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253453356,"owners_count":21911082,"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":["extracting","golang","html","scraping","xml","xpath"],"created_at":"2024-08-03T15:01:14.356Z","updated_at":"2025-05-10T17:31:40.016Z","avatar_url":"https://github.com/antchfx.png","language":"Go","funding_links":[],"categories":["XML","Libraries for creating HTTP middlewares"],"sub_categories":["Routers","路由器","创建http中间件的代码库","高级控制台界面","高級控制台界面"],"readme":"xquery\n====\n[![Build Status](https://travis-ci.org/antchfx/xquery.svg?branch=master)](https://travis-ci.org/antchfx/xquery)\n[![Coverage Status](https://coveralls.io/repos/github/antchfx/xquery/badge.svg?branch=master)](https://coveralls.io/github/antchfx/xquery?branch=master)\n[![GoDoc](https://godoc.org/github.com/antchfx/xquery?status.svg)](https://godoc.org/github.com/antchfx/xquery)\n[![Go Report Card](https://goreportcard.com/badge/github.com/antchfx/xquery)](https://goreportcard.com/report/github.com/antchfx/xquery)\n\n\u003e NOTE: This package is deprecated. Recommends use [htmlquery](https://github.com/antchfx/htmlquery) and [xmlquery](https://github.com/antchfx/xmlquery) package, get latest version to fixed some issues.\n\nOverview\n===\n\nGolang package, lets you extract data from HTML/XML documents using XPath expression.\n\nList of supported XPath functions you can found here [XPath Package](https://github.com/antchfx/xpath).\n\nInstallation\n====\n\n\u003e go get github.com/antchfx/xquery\n\n\nHTML Query [![GoDoc](https://godoc.org/github.com/antchfx/xquery/html?status.svg)](https://godoc.org/github.com/antchfx/xquery/html)\n===\n\nExtract data from HTML document.\n\n```go\npackage main\n\nimport (\n\t\"github.com/antchfx/xpath\"\n\t\"github.com/antchfx/xquery/html\"\n)\n\nfunc main() {\n\t// Load HTML file.\n\tf, err := os.Open(`./examples/test.html`)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// Parse HTML document.\n\tdoc, err := htmlquery.Parse(f)\n\tif err != nil{\n\t\tpanic(err)\n\t}\n\n\t// Option 1: using xpath's expr to matches nodes.\n\texpr := xpath.MustCompile(\"count(//div[@class='article'])\")\n\tfmt.Printf(\"%f \\n\", expr.Evaluate(htmlquery.CreateXPathNavigator(doc)).(float64))\n\n\texpr = xpath.MustCompile(\"//a/@href\")\n\titer := expr.Evaluate(htmlquery.CreateXPathNavigator(doc)).(*xpath.NodeIterator)\n\tfor iter.MoveNext() {\n\t\tfmt.Printf(\"%s \\n\", iter.Current().Value()) // output href\n\t}\n\n\t// Option 2: using build-in functions Find() to matches nodes.\n\tfor _, n := range htmlquery.Find(doc, \"//a/@href\") {\n\t\tfmt.Printf(\"%s \\n\", htmlquery.SelectAttr(n, \"href\")) // output href\n\t}\n}\n```\n\nXML Query [![GoDoc](https://godoc.org/github.com/antchfx/xquery/xml?status.svg)](https://godoc.org/github.com/antchfx/xquery/xml)\n===\nExtract data from XML document.\n\n```go\npackage main\n\nimport (\n\t\"github.com/antchfx/xpath\"\n\t\"github.com/antchfx/xquery/xml\"\n)\n\nfunc main() {\n\t// Load XML document from file.\n\tf, err := os.Open(`./examples/test.xml`)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// Parse XML document.\n\tdoc, err := xmlquery.Parse(f)\n\tif err != nil{\n\t\tpanic(err)\n\t}\n\n\t// Option 1: using xpath's expr to matches nodes.\n\n\t// sum all book's price via Evaluate()\n\texpr, err := xpath.Compile(\"sum(//book/price)\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"total price: %f\\n\", expr.Evaluate(xmlquery.CreateXPathNavigator(doc)).(float64))\n\n\tfor _, n := range xmlquery.Find(doc, \"//book\") {\n\t\tfmt.Printf(\"%s : %s \\n\", n.SelectAttr(\"id\"), xmlquery.FindOne(n, \"title\").InnerText())\n\t}\n\t\n\t// Option 2: using build-in functions FindOne() to matches node.\n\tn := xmlquery.FindOne(doc, \"//book[@id='bk104']\")\n\tfmt.Printf(\"%s \\n\", n.OutputXML(true))\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantchfx%2Fxquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantchfx%2Fxquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantchfx%2Fxquery/lists"}