{"_id":"@atlach/html-extract","name":"@atlach/html-extract","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@atlach/html-extract","version":"0.1.0","description":"Get information using the string of the specified rule","type":"module","main":"./dist/html-extract.cjs","module":"./dist/html-extract.mjs","browser":"dist/html-extract.browser.js","license":"MIT","scripts":{"test":"jest","build":"rimraf dist && rolldown -c"},"keywords":["crawler"],"author":{"name":"Milcery","email":"milcery@qq.com","url":"https://github.com/milcery/html-extract"},"dependencies":{"cheerio":"^1.0.0"},"devDependencies":{"@types/jest":"^29.5.14","@types/node":"^18.19.75","jest":"^29.7.0","rimraf":"^6.0.1","rolldown":"1.0.0-beta.3","ts-jest":"^29.2.5","typescript":"^5.7.3"},"repository":{"type":"git","url":"git+https://github.com/milcery/html-extract.git"},"bugs":{"url":"https://github.com/milcery/html-extract/issues"},"jest":{"moduleFileExtensions":["ts","js"],"transform":{"\\.ts$":"ts-jest"},"testRegex":"/test/.*\\.test.(ts|js)$"},"_id":"@atlach/html-extract@0.1.0","gitHead":"81a1fdd31972517e3c48dee565a99d39d3e96338","homepage":"https://github.com/milcery/html-extract#readme","_nodeVersion":"20.18.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-x+Clcx2jTnwAMmngFhePiK4V5W3rT2iLNZTkrgDgpIBXadgeFjQKogilRMnH7z6AqcGH1czXZuIYHYIi2WtfWQ==","shasum":"397be38a2359c117a88682941386607f24740266","tarball":"https://registry.npmjs.org/@atlach/html-extract/-/html-extract-0.1.0.tgz","fileCount":6,"unpackedSize":18673,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDOrrxpHQ5ZMKprOQbaNmc/4EK0hBnhWrDPZiqoLL0PRAIhALT++dpFIPBZVXtSiK+ecfWtGLoxcPeNgDFS6nyQ8yih"}]},"_npmUser":{"name":"milcery","email":"milcery@qq.com"},"directories":{},"maintainers":[{"name":"milcery","email":"milcery@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/html-extract_0.1.0_1738807214574_0.9389769890479924"},"_hasShrinkwrap":false}},"time":{"created":"2025-02-06T02:00:14.490Z","0.1.0":"2025-02-06T02:00:14.783Z","modified":"2025-02-06T02:00:15.071Z"},"maintainers":[{"name":"milcery","email":"milcery@qq.com"}],"description":"Get information using the string of the specified rule","homepage":"https://github.com/milcery/html-extract#readme","keywords":["crawler"],"repository":{"type":"git","url":"git+https://github.com/milcery/html-extract.git"},"author":{"name":"Milcery","email":"milcery@qq.com","url":"https://github.com/milcery/html-extract"},"bugs":{"url":"https://github.com/milcery/html-extract/issues"},"license":"MIT","readme":"# @atlach/html-extract\n\nGet information using the string of the specified rule\n\n## Usage\n\n### Nodejs\n```javascript\nconst HTML = `\n<div>\n  <a id=\"link\" class=\"link\" href=\"//github.com\" data-id=\"link\">Github</a>\n\n  <dl>\n    <dt>title</dt>\n    <dd><p>content</p></dd>\n  </dl>\n\n  <section>\n    prefix<u>123</u>suffix\n  </section>\n\n  <ul>\n    <li data-index=\"1\">\n      <a href=\"//a.com/id1/101\">(1)</a>\n    </li>\n    <li data-index=\"2\">\n      <a href=\"//a.com/id1/102\">(2)</a>\n    </li>\n    <li data-index=\"3\">\n      <a href=\"//a.com/id1/103\">(3)</a>\n    </li>\n    <li data-index=\"4\">\n      <a href=\"//a.com/id1/104\">(4)</a>\n    </li>\n  </ul>\n</div>\n`\nimport HtmlExtract from '@atlach/html-extract';  // ES module\n// const HtmlExtract = require('@atlach/html-extract').default; // Commonjs\n\nconst he = new HtmlExtract(HTML);\n\n// Get data\nhe.query();\n// Add custom function\nhe.useFilter();\n```\n\n### Browser\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js\"></script>\n<script src=\"https://cdn.jsdelivr.net/npm/@atlach/html-extract@0.1.0/dist/html-extract.browser.js\"></script>\n\n<script>\n  document.addEventListener('load', () => {\n    const he = new HtmlExtract();\n\n    // Get data\n    he.query();\n    // Add custom function\n    he.useFilter();\n  });\n</script>\n```\n\n\n## Grammar\n- Attribute related `:AttributeName`, case: `:href`\n- Remove dom `-Tag`, case `-p` Remove p tag\n- Filter method: `| functionName(parameter1, ..., parameterN)`, case: `| prefix(a, b)`\n  Other forms `| functionName((parameter1), ..., (parameterN))` Parameter wrap(), `| functionName` no parameters required\n\n### attribute\n\n```javascript\nhe.query('.link :href')               // output -> //github.com\nhe.query('.link :data-id')            // output -> link\n```\n\n### Filter method\n\nSelf-filtering methods\n- `| html`\n- `| text`\n- `| prefix`\n- `| prefix`\n- `| suffix`\n- `| trim`\n- `| eq`\n- `| filter`\n\n### html or text\n```javascript\nhe.query('.link | text')              // output -> Github\nhe.query('dd | html')                 // output -> <p>content</p>\n```\n\n### delete dom\n```javascript\nhe.query('section -u | text | trim');        // output -> prefixsuffix\n```\n\n### add prefix or suffix\n```javascript\nhe.query('.link :href | prefix(https:)')                     // output -> https://github.com\nhe.query('.link :href | suffix(?q=123)')                     // output -> //github.com?q=123\nhe.query('.link :href | prefix(https:) | suffix(?q=123)')    // output -> https://github.com?q=123\n```\n\n### eq\n```javascript\nhe.query('ul li:eq(2) :data-index')        // output -> 3\nhe.query('ul li | eq(2) :data-index')      // output -> 3\n```\n\n### filter text\n\n```javascript\nhe.query('ul li:eq(2) a :href')                    // output -> //a.com/id1/103\n// Filter out '1' and '/'\nhe.query('ul li:eq(2) a :href | filter(1, /)')     // output -> a.comid03\n```\n\n\n### list\n\ngrammar\n- Get one: `| array(Rule)`\n- Two-dimensional array: `| array((Rule1), (Rule2))`\n- Object data: `| array(Key1 => (Rule1), Key2 => (Rule2))`\n\nGet one\n\n```javascript\nhe.query('ul li | array(| text | trim)')\n\n// output ->\n  [\n    '(1)',\n    '(2)',\n    '(3)',\n    '(4)'\n  ]\n```\n\nTwo-dimensional array\nNote: The parameter is best to add `()`\n\n```javascript\nhe.query('ul li | array((:data-index), (a | text))')\n\n// output ->\n  [\n    ['1', '(1)'],\n    ['2', '(2)'],\n    ['3', '(3)'],\n    ['4', '(4)']\n  ];\n```\n\nObject data\n=> The front is the key, => The following is the rule, the rule is best to be wrapped with ()\n\n```javascript\nhe.query('ul a | array(href => (:href | prefix(https:)), title => (| text))')\n\n// output ->\n  [\n    { href: 'https://a.com/id1/101', title: '(1)' },\n    { href: 'https://a.com/id1/102', title: '(2)' },\n    { href: 'https://a.com/id1/103', title: '(3)' },\n    { href: 'https://a.com/id1/104', title: '(4)' }\n  ];\n```\n\n### Custom filtering methods\n\n```javascript\nhe.useFilter('prefixAndSuffix', (val, prefix, suffix) => prefix + val + suffix)\n\nhe.query('.link :href | prefixAndSuffix(https:, ?q=123)')   // output -> https://github.com?q=123\n```\n\n\n","readmeFilename":"README.md"}