{"id":39536126,"url":"https://github.com/hieuvp/xpath-html","last_synced_at":"2026-01-18T06:33:20.731Z","repository":{"id":40771992,"uuid":"260366653","full_name":"hieuvp/xpath-html","owner":"hieuvp","description":"Easily use XPath to locate any element in an HTML DOM page.","archived":false,"fork":false,"pushed_at":"2023-03-04T15:52:54.000Z","size":510,"stargazers_count":14,"open_issues_count":11,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-22T21:58:16.384Z","etag":null,"topics":["dom","html","xpath","xpath-html"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/xpath-html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hieuvp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-05-01T02:53:02.000Z","updated_at":"2024-04-29T20:31:04.000Z","dependencies_parsed_at":"2024-06-18T21:29:29.254Z","dependency_job_id":"33c48d9b-e0fc-42f0-945c-7a84c1a5ab5a","html_url":"https://github.com/hieuvp/xpath-html","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/hieuvp/xpath-html","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hieuvp%2Fxpath-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hieuvp%2Fxpath-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hieuvp%2Fxpath-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hieuvp%2Fxpath-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hieuvp","download_url":"https://codeload.github.com/hieuvp/xpath-html/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hieuvp%2Fxpath-html/sbom","scorecard":{"id":464334,"data":{"date":"2025-08-11","repo":{"name":"github.com/hieuvp/xpath-html","commit":"7d61130356ae7c85780775eec889e8edaea474d9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/19 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/hieuvp/xpath-html/release.yml/master?enable=pin","Warn: npmCommand not pinned by hash: scripts/clean-install.sh:9","Info:   0 out of   8 GitHub-owned GitHubAction dependencies pinned","Info:   4 out of   5 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 17 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"33 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-h6q6-9hqw-rwfv","Warn: Project is vulnerable to: GHSA-5fg8-2547-mr8q","Warn: Project is vulnerable to: GHSA-crh6-fp67-6883","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T12:03:38.836Z","repository_id":40771992,"created_at":"2025-08-19T12:03:38.836Z","updated_at":"2025-08-19T12:03:38.836Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28531997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"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":["dom","html","xpath","xpath-html"],"created_at":"2026-01-18T06:33:20.675Z","updated_at":"2026-01-18T06:33:20.726Z","avatar_url":"https://github.com/hieuvp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XPath HTML\n\n[![CI](https://github.com/hieuvp/xpath-html/workflows/CI/badge.svg?branch=master)](https://github.com/hieuvp/xpath-html/actions?query=workflow%3ACI+branch%3Amaster)\n[![Release](https://github.com/hieuvp/xpath-html/workflows/release/badge.svg)](https://github.com/hieuvp/xpath-html/actions?query=workflow%3Arelease)\n[![NPM](https://img.shields.io/npm/v/xpath-html.svg)](https://www.npmjs.com/package/xpath-html)\n[![Downloads](https://img.shields.io/npm/dm/xpath-html.svg)](https://www.npmjs.com/package/xpath-html)\n\n\u003cbr /\u003e\n\n**XPath** stands for **XML Path Language**.\u003cbr /\u003e\nIt provides a flexible **non-XML syntax** to address (point to) different parts of an **XML document**.\n\n\u003cbr /\u003e\n\n\u003e With the [**XPath HTML**](#xpath-html),\n\u003e this will enable us to use such a powerful tool,\n\u003e navigating through the **HTML DOM** by **XPath expression**.\n\n\u003cbr /\u003e\n\nIf you want to learn more about **XPath** and\nknow how to use different **XPath expression** for finding complex or dynamic elements,\ntake a visit to this concise tutorial\n[here](https://github.com/hieuvp/learning-automation-tools/blob/master/xpath/README.md).\n\n## Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Installation](#installation)\n- [Usages](#usages)\n  - [Hello XPath from HTML World](#hello-xpath-from-html-world)\n  - [`fromPageSource(html).findElement(expression)`](#frompagesourcehtmlfindelementexpression)\n  - [`fromPageSource(html).findElements(expression)`](#frompagesourcehtmlfindelementsexpression)\n  - [`fromNode(xhtml).findElement(expression)`](#fromnodexhtmlfindelementexpression)\n  - [`fromNode(xhtml).findElements(expression)`](#fromnodexhtmlfindelementsexpression)\n  - [`node.getTagName()`](#nodegettagname)\n  - [`node.getText()`](#nodegettext)\n  - [`node.getAttribute(name)`](#nodegetattributename)\n- [Dependencies](#dependencies)\n- [License](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Installation\n\n[`xpath-html`](https://www.npmjs.com/package/xpath-html) is available as a package on [NPM](https://www.npmjs.com/),\nopen up a **Terminal** and enter the following command:\n\n```shell script\nnpm install --save xpath-html\n```\n\n## Usages\n\n### Hello XPath from HTML World\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/hello.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/hello.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\n// Assuming you have an html file locally,\n// Here is the content that I scraped from www.shopback.sg\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\n\n// Don't worry about the input much,\n// you are able to use the HTML response of an HTTP request,\n// as long as the argument is a string type, everything should be fine.\nconst node = xpath.fromPageSource(html).findElement(\"//*[contains(text(), 'with love')]\");\n\nconsole.log(`The matched tag name is \"${node.getTagName()}\"`);\nconsole.log(`Your full text is \"${node.getText()}\"`);\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n```shell script\n# A fast way to download .html file above\n$ curl https://www.shopback.sg -o shopback.html\n\n# Or from my GitHub examples\n$ curl -O https://raw.githubusercontent.com/hieuvp/xpath-html/master/examples/shopback.html\n```\n\nBang 💥 **Output** should be something looks like:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/hello.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/hello.txt --\u003e\n\n```txt\nThe matched tag name is \"div\"\nYour full text is \"Made with love by\"\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n\u003cbr /\u003e\n\nIt is understandable, right? \u003cbr /\u003e\nNow, you can scroll down the APIs below and diving into details.\n\n\u003cbr /\u003e\n\n### `fromPageSource(html).findElement(expression)`\n\n\u003e Locate an element on a page,\n\u003e the returned node is a representation of the underlying DOM.\n\n**Arguments:**\n\n| Name         | Type     | Description                |\n| ------------ | -------- | -------------------------- |\n| `html`       | `string` | Input HTML page's source   |\n| `expression` | `string` | The given XPath expression |\n\n**Returns:** `Node`\n\n**Example**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/fromPageSource.findElement.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/fromPageSource.findElement.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\nconst node = xpath.fromPageSource(html).findElement(\"//*[text()='Made with love by']\");\n\nconsole.log(node.toString());\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n**Result**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/fromPageSource.findElement.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/fromPageSource.findElement.txt --\u003e\n\n```txt\n\u003cdiv xmlns=\"http://www.w3.org/1999/xhtml\"\u003eMade with love by\u003c/div\u003e\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n\u003cbr /\u003e\n\n### `fromPageSource(html).findElements(expression)`\n\n\u003e Search for multiple elements on a page.\n\n**Arguments:**\n\n| Name         | Type     | Description                |\n| ------------ | -------- | -------------------------- |\n| `html`       | `string` | Input HTML page's source   |\n| `expression` | `string` | The given XPath expression |\n\n**Returns:** `Array\u003cNode\u003e`\n\n**Example**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/fromPageSource.findElements.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/fromPageSource.findElements.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\nconst nodes = xpath\n  .fromPageSource(html)\n  .findElements(\"//img[starts-with(@src, 'https://cloud.shopback.com')]\");\n\nconsole.log(\"Number of nodes found:\", nodes.length);\nconsole.log(\"nodes[0]:\", nodes[0].toString());\nconsole.log(\"nodes[1]:\", nodes[1].toString());\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n**Result**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/fromPageSource.findElements.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/fromPageSource.findElements.txt --\u003e\n\n```txt\nNumber of nodes found: 158\nnodes[0]: \u003cimg src=\"https://cloud.shopback.com/raw/upload/static/images/navbar/sb-logo.png\" xmlns=\"http://www.w3.org/1999/xhtml\"/\u003e\nnodes[1]: \u003cimg src=\"https://cloud.shopback.com/raw/upload/static/images/navbar/desktop/icon-raf.svg\" xmlns=\"http://www.w3.org/1999/xhtml\"/\u003e\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n\u003cbr /\u003e\n\n### `fromNode(xhtml).findElement(expression)`\n\n\u003e Select an element against an XHTML format.\u003cbr /\u003e\n\u003e Similar to [`fromPageSource(html).findElement(expression)`](#frompagesourcehtmlfindelementexpression),\n\u003e but it is for a subset of an `html` page this time.\n\n**Arguments:**\n\n| Name         | Type               | Description                                                                           |\n| ------------ | ------------------ | ------------------------------------------------------------------------------------- |\n| `xhtml`      | `Node` or `string` | Either a **returned node** from a query\u003cbr /\u003eor an **xhtml string** with a good shape |\n| `expression` | `string`           | The given XPath expression                                                            |\n\n**Returns:** `Node`\n\n**Notes:**\n\n- The input `xhtml` must have a namespace of `xmlns=\"http://www.w3.org/1999/xhtml\"` \u003cbr /\u003e\n  e.g. `\u003cdiv xmlns=\"http://www.w3.org/1999/xhtml\"\u003eMade with love by\u003c/div\u003e`\n\n**Example**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/fromNode.findElement.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/fromNode.findElement.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\nconst group = xpath.fromPageSource(html).findElement(\"//div[@class='ui-store-group']\");\n\nconst node = xpath.fromNode(group).findElement(\"//a[@href='/aliexpress']\");\n\nconsole.log(node.toString());\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n**Result**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/fromNode.findElement.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/fromNode.findElement.txt --\u003e\n\n```txt\n\u003ca class=\"store-logo-wrapper\" href=\"/aliexpress\" title=\"AliExpress Coupons \u0026amp; Promo Codes\" xmlns=\"http://www.w3.org/1999/xhtml\"\u003e\u003cimg class=\"store-logo\" src=\"https://cloud.shopback.com/t_sd_250_pad,f_auto,fl_lossy,q_auto/sg-store/49/49_logo_86958e96.png\" alt=\"AliExpress Coupons \u0026amp; Promo Codes\"/\u003e\u003c/a\u003e\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n\u003cbr /\u003e\n\n### `fromNode(xhtml).findElements(expression)`\n\n\u003e Select multiple elements against an XHTML format.\u003cbr /\u003e\n\u003e Same as [`fromPageSource(html).findElements(expression)`](#frompagesourcehtmlfindelementsexpression),\n\u003e however it is being used for querying from a part of an `html`.\n\n**Arguments:**\n\n| Name         | Type               | Description                                                                           |\n| ------------ | ------------------ | ------------------------------------------------------------------------------------- |\n| `xhtml`      | `Node` or `string` | Either a **returned node** from a query\u003cbr /\u003eor an **xhtml string** with a good shape |\n| `expression` | `string`           | The given XPath expression                                                            |\n\n**Returns:** `Array\u003cNode\u003e`\n\n**Notes:**\n\n- The input `xhtml` must have a namespace of `xmlns=\"http://www.w3.org/1999/xhtml\"` \u003cbr /\u003e\n  e.g. `\u003cdiv xmlns=\"http://www.w3.org/1999/xhtml\"\u003eMade with love by\u003c/div\u003e`\n\n**Example**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/fromNode.findElements.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/fromNode.findElements.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\nconst group = xpath.fromPageSource(html).findElement(\"//div[@class='ui-store-group']\");\n\nconst nodes = xpath.fromNode(group).findElements(\"//img[contains(@src,'shopily')]\");\n\nconsole.log(\"Number of nodes found:\", nodes.length);\nconsole.log(\"nodes[0]:\", nodes[0].toString());\nconsole.log(\"nodes[1]:\", nodes[1].toString());\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n**Result**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/fromNode.findElements.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/fromNode.findElements.txt --\u003e\n\n```txt\nNumber of nodes found: 2\nnodes[0]: \u003cimg class=\"store-logo\" src=\"https://shopily-sg.s3.amazonaws.com/uploads/stores/504/504_logo_200c4121.png\" alt=\"zChocolat Coupons \u0026amp; Promo Codes\" xmlns=\"http://www.w3.org/1999/xhtml\"/\u003e\nnodes[1]: \u003cimg class=\"store-logo\" src=\"https://shopily-sg.s3.amazonaws.com/uploads/stores/2498/2498_logo_81f0a24d.png\" alt=\"Bed Bath \u0026amp; Beyond Coupons \u0026amp; Promo Codes\" xmlns=\"http://www.w3.org/1999/xhtml\"/\u003e\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n\u003cbr /\u003e\n\n### `node.getTagName()`\n\n\u003e Retrieve the node's tag name.\n\n**Arguments:** None\n\n**Returns:** `string`\n\n**Example**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/node.getTagName.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/node.getTagName.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\nconst node = xpath.fromPageSource(html).findElement(\"//*[text()='Made with love by']\");\n\nconsole.log(\"Single node's tag name:\", node.getTagName());\n\nconst nodes = xpath\n  .fromPageSource(html)\n  .findElements(\"//img[starts-with(@src, 'https://cloud.shopback.com')]\");\n\nconsole.log(\"First nodes[0] tag name:\", nodes[0].getTagName());\nconsole.log(\"Second nodes[1] tag name:\", nodes[1].getTagName());\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n**Result**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/node.getTagName.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/node.getTagName.txt --\u003e\n\n```txt\nSingle node's tag name: div\nFirst nodes[0] tag name: img\nSecond nodes[1] tag name: img\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n\u003cbr /\u003e\n\n### `node.getText()`\n\n\u003e Get the visible **innerText** of the node.\n\n**Arguments:** None\n\n**Returns:** `string`\n\n**Example**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/node.getText.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/node.getText.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\nconst node = xpath.fromPageSource(html).findElement(\"//*[text()='Made with love by']\");\n\nconsole.log(\"Text of the node:\", node.getText());\n\nconst nodes = xpath\n  .fromPageSource(html)\n  .findElements(\"//div[@id='home-page-container']//*[@class='title-text']\");\n\nconsole.log(\"Text of nodes[0]:\", nodes[0].getText());\nconsole.log(\"Text of nodes[1]:\", nodes[1].getText());\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n**Result**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/node.getText.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/node.getText.txt --\u003e\n\n```txt\nText of the node: Made with love by\nText of nodes[0]: Up to 10.0% Cash Rewards\nText of nodes[1]: Up to 7.0% Cashback\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n\u003cbr /\u003e\n\n### `node.getAttribute(name)`\n\n\u003e Retrieve the current value of the given attribute of this node.\n\n**Arguments:**\n\n| Name   | Type     | Description                        |\n| ------ | -------- | ---------------------------------- |\n| `name` | `string` | The name of the attribute to query |\n\n**Returns:** `string`\n\n**Example**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=examples/node.getAttribute.js) --\u003e\n\u003c!-- The below code snippet is automatically added from examples/node.getAttribute.js --\u003e\n\n```js\nconst fs = require(\"fs\");\nconst xpath = require(\"xpath-html\");\n\nconst html = fs.readFileSync(`${__dirname}/shopback.html`, \"utf8\");\nconst node = xpath.fromPageSource(html).findElement(\"//a[text()='View All Popular Stores']\");\n\nconsole.log(\"The href value:\", node.getAttribute(\"href\"));\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n**Result**:\n\n\u003c!-- AUTO-GENERATED-CONTENT:START (CODE:src=output/node.getAttribute.txt) --\u003e\n\u003c!-- The below code snippet is automatically added from output/node.getAttribute.txt --\u003e\n\n```txt\nThe href value: /all-stores\n```\n\n\u003c!-- AUTO-GENERATED-CONTENT:END --\u003e\n\n## Dependencies\n\nSpecial thanks to all contributors of these libraries\nwhich are the foundation of what `xpath-html` was built upon.\n\n1. [xpath](https://github.com/goto100/xpath)\n1. [xmldom](https://github.com/jindw/xmldom)\n1. [xmlserializer](https://github.com/cburgmer/xmlserializer)\n1. [parse5](https://github.com/inikulin/parse5)\n\n## License\n\nMIT\n\nMade with ❤ from [ShopBack](https://www.shopback.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhieuvp%2Fxpath-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhieuvp%2Fxpath-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhieuvp%2Fxpath-html/lists"}