{"id":34164491,"url":"https://github.com/avan06/htmlq","last_synced_at":"2026-01-20T19:10:24.693Z","repository":{"id":174398022,"uuid":"652175505","full_name":"avan06/htmlq","owner":"avan06","description":"A command-line tool that allows you to query HTML using CSS selectors or XPATH and retrieve the corresponding text content (similar to JavaScript's `document.querySelector(query).textContent`)","archived":false,"fork":false,"pushed_at":"2023-08-16T14:32:01.000Z","size":35,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-06-21T19:46:08.846Z","etag":null,"topics":["command-line","command-line-tools","css-selectors","html","queryselector","textcontent","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/avan06.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}},"created_at":"2023-06-11T10:31:48.000Z","updated_at":"2024-04-03T03:05:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"bb89414a-3c6f-40fb-a9a2-784c9303545c","html_url":"https://github.com/avan06/htmlq","commit_stats":null,"previous_names":["avan06/htmlq"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/avan06/htmlq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avan06%2Fhtmlq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avan06%2Fhtmlq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avan06%2Fhtmlq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avan06%2Fhtmlq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/avan06","download_url":"https://codeload.github.com/avan06/htmlq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/avan06%2Fhtmlq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28609837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T18:56:40.769Z","status":"ssl_error","status_checked_at":"2026-01-20T18:54:26.653Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["command-line","command-line-tools","css-selectors","html","queryselector","textcontent","xpath"],"created_at":"2025-12-15T09:52:19.878Z","updated_at":"2026-01-20T19:10:24.589Z","avatar_url":"https://github.com/avan06.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"htmlq v1.1.1\n====\n\n`htmlq` is a `command-line` tool that allows you to query HTML using `CSS selectors` or `XPATH` and retrieve the corresponding `text content` (similar to JavaScript's `document.querySelector(query).textContent`).\n\n\n# Installation\n\n```\ngo install github.com/avan06/htmlq@latest\n```\n\n# Usage\n\n```\nusage: htmlq 1.1.1 [-h|--help] [-f|--file \"\u003cvalue\u003e\"] [-t|--text \"\u003cvalue\u003e\"]\n                   [-u|--url \"\u003cvalue\u003e\"] [-x|--XPATH] [-a|--SelectorAll]\n                   [-r|--ResultAsNode] [--Trim] [--RemoveNewLine]\n                   [--RemoveConsecutiveWhiteChars] [-l|--PrintLastResult]\n                   [--PrintLastResultTemp] [--PrintQuerysInAllResult]\n                   [--PrintTextInAllResult \"\u003cvalue\u003e\"] [-H|--headers \"\u003cvalue\u003e\"\n                   [-H|--headers \"\u003cvalue\u003e\" ...]] [-v|--verbose] -q|--querys\n                   \"\u003cvalue\u003e\" [-q|--querys \"\u003cvalue\u003e\" ...]\n\n                   A command-line tool that allows you to query HTML using CSS\n                   selectors or XPATH and retrieve the corresponding text\n                   content (similar to JavaScript's\n                   `document.querySelector(query).textContent`)\n\nArguments:\n\n  -h  --help                         Print help information\n  -f  --file                         Enter the relative or absolute path of the\n                                     HTML file\n  -t  --text                         Enter the HTML text content\n  -u  --url                          Enter the URL of the HTML\n  -x  --XPATH                        Enable default XPATH query syntax instead\n                                     of CSS Selectors. Default: false\n  -a  --SelectorAll                  Enable the SelectorAll mechanism. When\n                                     there are multiple results for a single\n                                     query, it will return all the results\n                                     (similar to querySelectorAll). By default,\n                                     it is not enabled, and only a single\n                                     result is returned (similar to\n                                     querySelector).. Default: false\n  -r  --ResultAsNode                 Enable using the Node from the previous\n                                     query result as the current query's root\n                                     Node. Default: false\n      --Trim                         trim the result text\n      --RemoveNewLine                remove new line in the result text\n      --RemoveConsecutiveWhiteChars  remove consecutive white characters in the\n                                     result text\n  -l  --PrintLastResult              Enable printing the content of the last\n                                     result in the output when using the\n                                     \"#lastresult\" syntax in the query.\n                                     Default: false\n      --PrintLastResultTemp          Enable printing the temporary content of\n                                     the source data as last result in the\n                                     output, when using the \"#lastresult\"\n                                     syntax in query. Default: false\n      --PrintQuerysInAllResult       Enable printing of query conditions in\n                                     results.. Default: false\n      --PrintTextInAllResult         Enter a text content for printing in all\n                                     results. If the content contains \"#{serial\n                                     number}\", the content of the specified\n                                     serial number's result will be\n                                     automatically printed in all results\n                                     following that serial number.\n  -H  --headers                      When the query item is a table or multiple\n                                     td fields, you can enter corresponding\n                                     names for each individual field in a\n                                     single query using the format \"#{serial\n                                     number}:header1Name;header2Name;header3Name;...\",\n                                     where the serial number represents the Nth\n                                     query starting from zero.\n  -v  --verbose                      verbose\n  -q  --querys                       Enter a query value to retrieve the Node\n                                     Text of the target HTML. The default query\n                                     method is CSS Selectors, but it can be\n                                     changed to XPATH using \"-x\" or \"--XPATH\".\n                                     Both query methods can be mixed. When a\n                                     query starts with \"C:\", it represents CSS\n                                     Selectors, and when it starts with \"X:\",\n                                     it represents XPATH.\n\n        You can enter multiple query values separated by spaces and return all the\n                                     results.\n\n        * When the \"--ResultNode\" is enabled, you can use the following special query\n                                     values to change the current position of\n                                     the HTML Node:\n          - Parent: Move the Node up one level\n          - NextSibling: Move the Node to the next sibling in the same level\n          - PrevSibling: Move the Node to the previous sibling in the same level\n          - FirstChild: Move the Node to the first child in the same level\n          - LastChild: Move the Node to the last child in the same level\n          - reset: Restore the Node to the root node of the original input\n\n        * When using the \"#lastresult\" query syntax, the text content of the previous\n                                     query will automatically replace\n                                     \"#lastresult\".\n\n        Example: --ResultNode -q Query1 Parent Query2 NextSibling Query3 LastChild\n                                     C:Query4 reset X:Query5\n```\n\n# Examples\n\nNote: In command-line, to break a line in Linux you use \"\\\\\", while in Windows you use \"^\".\n\n```Shell\nhtmlq --XPATH --SelectorAll -vv --PrintLastResult \n-t \"\u003ctable class='ws-table-all notranslate'\u003e\u003ctbody\u003e\u003ctr\u003e\u003cth\u003eTag\u003c/th\u003e\u003cth\u003eDescription\u003c/th\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;table\u0026gt;\u003c/td\u003e\u003ctd\u003eDefines a table\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;th\u0026gt;\u003c/td\u003e\u003ctd\u003eDefines a header cell in a table\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;tr\u0026gt;\u003c/td\u003e\u003ctd\u003eDefines a row in a table\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;td\u0026gt;\u003c/td\u003e\u003ctd\u003eDefines a cell in a table\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;caption\u0026gt;\u003c/td\u003e\u003ctd\u003eDefines a table caption\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;colgroup\u0026gt;\u003c/td\u003e\u003ctd\u003eSpecifies a group of one or more columns in a table for formatting\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;col\u0026gt;\u003c/td\u003e\u003ctd\u003eSpecifies column properties for each column within a colgroup element\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;thead\u0026gt;\u003c/td\u003e\u003ctd\u003eGroups the header content in a table\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;tbody\u0026gt;\u003c/td\u003e\u003ctd\u003eGroups the body content in a table\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u0026lt;tfoot\u0026gt;\u003c/td\u003e\u003ctd\u003eGroups the footer content in a table\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\" \n--headers \"#1:Tag1;Description1\" --headers \"#3:Tag3;Description3\" \n-q \"//table[contains(@class,'ws-table-all')]//tr[5]\" \n\"C:table.ws-table-all tr:nth-child(5)\" \n\"C:table.ws-table-all tr\" \n\"//table[contains(@class,'ws-table-all')]//tr[not(th)]\" \n\"//table[contains(@class,'ws-table-all')]//tr/td[1]\" \n\"//table[contains(@class,'ws-table-all')]//tr[contains(.,'#lastresult')]/td[2]\"\n```\n\n```Shell\n0: //table[contains(@class,'ws-table-all')]//tr[5]\n0-0:\n\u003ctd\u003e\nDefines a cell in a table\n```\n\n```Shell\n1: table.ws-table-all tr:nth-child(5)\n1-0:\nTag1:\u003ctd\u003e\nDescription1:Defines a cell in a table\n```\n\n```Shell\n2: table.ws-table-all tr\n2-0:\nTag\nDescription\n2-1:\n\u003ctable\u003e\nDefines a table\n2-2:\n\u003cth\u003e\nDefines a header cell in a table\n2-3:\n\u003ctr\u003e\nDefines a row in a table\n2-4:\n\u003ctd\u003e\nDefines a cell in a table\n2-5:\n\u003ccaption\u003e\nDefines a table caption\n2-6:\n\u003ccolgroup\u003e\nSpecifies a group of one or more columns in a table for formatting\n2-7:\n\u003ccol\u003e\nSpecifies column properties for each column within a colgroup element\n2-8:\n\u003cthead\u003e\nGroups the header content in a table\n2-9:\n\u003ctbody\u003e\nGroups the body content in a table\n2-10:\n\u003ctfoot\u003e\nGroups the footer content in a table\n```\n\n```Shell\n3: //table[contains(@class,'ws-table-all')]//tr[not(th)]\n3-0:\nTag3:\u003ctable\u003e\nDescription3:Defines a table\n3-1:\nTag3:\u003cth\u003e\nDescription3:Defines a header cell in a table\n3-2:\nTag3:\u003ctr\u003e\nDescription3:Defines a row in a table\n3-3:\nTag3:\u003ctd\u003e\nDescription3:Defines a cell in a table\n3-4:\nTag3:\u003ccaption\u003e\nDescription3:Defines a table caption\n3-5:\nTag3:\u003ccolgroup\u003e\nDescription3:Specifies a group of one or more columns in a table for formatting\n3-6:\nTag3:\u003ccol\u003e\nDescription3:Specifies column properties for each column within a colgroup element\n3-7:\nTag3:\u003cthead\u003e\nDescription3:Groups the header content in a table\n3-8:\nTag3:\u003ctbody\u003e\nDescription3:Groups the body content in a table\n3-9:\nTag3:\u003ctfoot\u003e\nDescription3:Groups the footer content in a table\n```\n\n```Shell\n4: //table[contains(@class,'ws-table-all')]//tr/td[1]\n4-0:\n\u003ctable\u003e\n4-1:\n\u003cth\u003e\n4-2:\n\u003ctr\u003e\n4-3:\n\u003ctd\u003e\n4-4:\n\u003ccaption\u003e\n4-5:\n\u003ccolgroup\u003e\n4-6:\n\u003ccol\u003e\n4-7:\n\u003cthead\u003e\n4-8:\n\u003ctbody\u003e\n4-9:\n\u003ctfoot\u003e\n```\n\n```Shell\n5: //table[contains(@class,'ws-table-all')]//tr[contains(.,'#lastresult')]/td[2]\n5-0:\n\u003ctable\u003e\nDefines a table\n5-1:\n\u003cth\u003e\nDefines a header cell in a table\n5-2:\n\u003ctr\u003e\nDefines a row in a table\n5-3:\n\u003ctd\u003e\nDefines a cell in a table\n5-4:\n\u003ccaption\u003e\nDefines a table caption\n5-5:\n\u003ccolgroup\u003e\nSpecifies a group of one or more columns in a table for formatting\n5-6:\n\u003ccol\u003e\nSpecifies column properties for each column within a colgroup element\n5-7:\n\u003cthead\u003e\nGroups the header content in a table\n5-8:\n\u003ctbody\u003e\nGroups the body content in a table\n5-9:\n\u003ctfoot\u003e\nGroups the footer content in a table\n```\n\n\n# Credits\n\n* [antchfx/htmlquery](https://github.com/antchfx/htmlquery)\n* [andybalholm/cascadia](https://github.com/andybalholm/cascadia)\n* [ericchiang/css](https://github.com/ericchiang/css)\n* [akamensky/argparse](https://github.com/akamensky/argparse)\n* [fatih/color](https://github.com/fatih/color)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favan06%2Fhtmlq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Favan06%2Fhtmlq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Favan06%2Fhtmlq/lists"}