{"id":13721831,"url":"https://github.com/GULPF/nimquery","last_synced_at":"2025-05-07T14:30:47.094Z","repository":{"id":23934338,"uuid":"100202902","full_name":"GULPF/nimquery","owner":"GULPF","description":"Nim library for querying HTML using CSS-selectors (like JavaScripts document.querySelector)","archived":false,"fork":false,"pushed_at":"2022-12-06T20:36:52.000Z","size":129,"stargazers_count":134,"open_issues_count":0,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T16:46:07.835Z","etag":null,"topics":["html","nim","scraping","web"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/GULPF.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","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":"2017-08-13T20:31:07.000Z","updated_at":"2025-02-11T18:13:35.000Z","dependencies_parsed_at":"2023-01-14T00:06:21.520Z","dependency_job_id":null,"html_url":"https://github.com/GULPF/nimquery","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fnimquery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fnimquery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fnimquery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fnimquery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GULPF","download_url":"https://codeload.github.com/GULPF/nimquery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252895488,"owners_count":21821169,"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","nim","scraping","web"],"created_at":"2024-08-03T01:01:21.927Z","updated_at":"2025-05-07T14:30:46.715Z","avatar_url":"https://github.com/GULPF.png","language":"Nim","readme":"# Nimquery ![CI](https://github.com/GULPF/nimquery/workflows/CI/badge.svg)\nA library for querying HTML using CSS selectors, like JavaScripts `document.querySelector`/`document.querySelectorAll`.\n\n## Installation\n\nNimquery is available on Nimble:\n```\nnimble install nimquery\n```\n\n## Usage\n```nim\nfrom xmltree import `$`\nfrom htmlparser import parseHtml\nimport nimquery\n\nlet html = \"\"\"\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\u003ctitle\u003eExample\u003c/title\u003e\u003c/head\u003e\n  \u003cbody\u003e\n    \u003cp\u003e1\u003c/p\u003e\n    \u003cp\u003e2\u003c/p\u003e\n    \u003cp\u003e3\u003c/p\u003e\n    \u003cp\u003e4\u003c/p\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n\"\"\"\nlet xml = parseHtml(html)\nlet elements = xml.querySelectorAll(\"p:nth-child(odd)\")\necho elements\n# =\u003e @[\u003cp\u003e1\u003c/p\u003e, \u003cp\u003e3\u003c/p\u003e]\n```\n\n## API\n\n```nim\nproc querySelectorAll*(root: XmlNode,\n                       queryString: string,\n                       options: set[QueryOption] = DefaultQueryOptions): seq[XmlNode]\n```\nGet all elements matching `queryString`.  \nRaises `ParseError` if parsing of `queryString` fails.  \nSee [Options](#options) for information about the `options` parameter.\n\n- - -\n\n```nim\nproc querySelector*(root: XmlNode,\n                    queryString: string,\n                    options: set[QueryOption] = DefaultQueryOptions): XmlNode\n```\nGet the first element matching `queryString`, or `nil` if no such element exists.  \nRaises `ParseError` if parsing of `queryString` fails.  \nSee [Options](#options) for information about the `options` parameter.\n\n- - -\n\n```nim\nproc parseHtmlQuery*(queryString: string,\n                     options: set[QueryOption] = DefaultQueryOptions): Query\n```\nParses a query for later use.  \nRaises `ParseError` if parsing of `queryString` fails.  \nSee [Options](#options) for information about the `options` parameter. \n\n- - -\n\n```nim\nproc exec*(query: Query,\n           root: XmlNode,\n           single: bool): seq[XmlNode]\n```\nExecute an already parsed query. If `single = true`, it will never return more than one element.\n\n### Options \u003ca name=\"options\"\u003e\u003c/a\u003e\nThe `QueryOption` enum contains flags for configuring the behavior when parsing/searching:\n\n- `optUniqueIds`: Indicates if id attributes should be assumed to be unique.\n- `optSimpleNot`: Indicates if only simple selectors are allowed as an argument to the `:not(...)` psuedo-class. Note that combinators are not allowed in the argument even if this flag is excluded.\n- `optUnicodeIdentifiers`: Indicates if unicode characters are allowed inside identifiers. Doesn't affect strings where unicode is always allowed.\n\nThe default options is defined as `const DefaultQueryOptions* = { optUniqueIds, optUnicodeIdentifiers, optSimpleNot }`.\n\nBelow is an example of using the options parameter to allow a complex `:not(...)` selector.\n\n```nim\nimport xmltree\nimport htmlparser\nimport streams\nimport nimquery\n\nlet html = \"\"\"\n\u003c!DOCTYPE html\u003e\n  \u003chtml\u003e\n    \u003chead\u003e\u003ctitle\u003eExample\u003c/title\u003e\u003c/head\u003e\n    \u003cbody\u003e\n      \u003cp\u003e1\u003c/p\u003e\n      \u003cp class=\"maybe-skip\"\u003e2\u003c/p\u003e\n      \u003cp class=\"maybe-skip\"\u003e3\u003c/p\u003e\n      \u003cp\u003e4\u003c/p\u003e\n    \u003c/body\u003e\n  \u003c/html\u003e\n\"\"\"\nlet xml = parseHtml(newStringStream(html))\nlet options = DefaultQueryOptions - { optSimpleNot }\nlet elements = xml.querySelectorAll(\"p:not(.maybe-skip:nth-child(even))\", options)\necho elements\n# =\u003e @[\u003cp\u003e1\u003c/p\u003e, \u003cp class=\"maybe-skip\"\u003e3\u003c/p\u003e, \u003cp\u003e4\u003c/p\u003e]\n```\n\n## Unsupported selectors\nNimquery supports all [CSS3 selectors](https://www.w3.org/TR/css3-selectors) except the following: `:root`, `:link`, `:visited`, `:active`, `:hover`, `:focus`, `:target`, `:lang(...)`, `:enabled`, `:disabled`, `:checked`, `::first-line`, `::first-letter`, `::before`, `::after`. These selectors will not be implemented because they don't make much sense in the situations where Nimquery is useful.\n","funding_links":[],"categories":["Web","Nim"],"sub_categories":["Parsing HTML","HTML Parsers"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGULPF%2Fnimquery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGULPF%2Fnimquery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGULPF%2Fnimquery/lists"}