{"_id":"@aghajari/jssoup","_rev":"1-bebba8b612e4f9c814617888b16dc6ee","name":"@aghajari/jssoup","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.2":{"name":"@aghajari/jssoup","version":"1.0.2","description":"JSSoup: the JavaScript HTML DOM parser for node.js","main":"index.js","dependencies":{"iconv":"^3.0.0"},"keywords":["jssoup","htmlparser","dom","html"],"author":{"name":"AmirHossein Aghajari"},"license":"Apache-2.0","scripts":{"test":"npm test.js"},"repository":{"type":"git","url":"git+https://github.com/Aghajari/JSSoup.git"},"bugs":{"url":"https://github.com/Aghajari/JSSoup/issues"},"homepage":"https://github.com/Aghajari/JSSoup#readme","devDependencies":{},"_id":"@aghajari/jssoup@1.0.2","_nodeVersion":"14.17.6","_npmVersion":"6.14.15","dist":{"integrity":"sha512-P2DbSzKL99zkGZHK26zAAS+csxLy7DJL1Wtyk66xE/rrBy003wa6X9fp8qzBsiBj0P8uA9IYl31z94DikxIWsg==","shasum":"d9c9b9b61485ec9599ac166977ecaf32ce859ae1","tarball":"https://registry.npmjs.org/@aghajari/jssoup/-/jssoup-1.0.2.tgz","fileCount":24,"unpackedSize":133247,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhNotYCRA9TVsSAnZWagAAeEUQAI5ZSUsqS6fZfoo9An+N\ndXh6CxqIq/t0O6wb8S6vQ6hcIliFMw6+G4Xwz3/GTBbNOO89YOhltAmidGjt\nhaFBT9imrzfWtT7GCN1qHxoL6/eYacvZmdLYpy+5m4QkLO8uFEqlOGXNw0Fw\ndvgjgjhmSqPWzk2ocFfwPyaw+h4NFnYnF2fXMmHKu7ZcxZuuEPATB6IWi22l\nZnBDxWGwDAjP06Akn4MF5f4TgZGQ6P5UFCnFKXdpnD4+8sa3+RjDCteymPwf\n2HV0bsoFUHKK+xGACLKDt30WaSsT/AE6vm6/ogJ/whEDhiI6zpBpQmSJPxDS\nSEmBN5zbBVkD1aH9lKnwv/Hwg1fftKvnpFO1qGNt3PJ1mV9dDouaFWFffkju\nE4GjEPLZV/Kzz6uvFKgvGK1OTRaapGf/LJzaTEuNEno+TLzPxDf7ShNfjLho\nq2ZpUCVocysvCs92HSGRyeniQ8g8mf5zNX0c1f4Aq+C4NNoPaw3QgTu4IRnM\nnTVTekCPwL3H+GK+9XlWNJ3ouSPLXsefkN/XG1jdSD3m+6wnXJkZ+mOuMsFi\n4D8rieFRzF5MNOVdTfkEKu6V/f414AfkPvQr75X/7KgxdNamNk70/GGsRn1m\nbIrsjAukXPM9bcNrnbF5JFyGRlFfq2TBqd45ltckt77wRLOyxsrwRsVIGcPu\n4sqK\r\n=2tc6\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICMKBHBo7NsSb1yGDjOMK/QN9GeSP6XLFy8iZQZEPTX3AiB35Z8GpFs1sFkV776pehTTA/TyJqApUmh7uheLjhgsTQ=="}]},"_npmUser":{"name":"aghajari","email":"amirhisein82.aa@gmail.com"},"directories":{},"maintainers":[{"name":"aghajari","email":"amirhisein82.aa@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jssoup_1.0.2_1630964568178_0.5146048433964971"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-06T21:42:48.116Z","1.0.2":"2021-09-06T21:42:48.341Z","modified":"2022-04-04T11:57:07.842Z"},"maintainers":[{"name":"aghajari","email":"amirhisein82.aa@gmail.com"}],"description":"JSSoup: the JavaScript HTML DOM parser for node.js","homepage":"https://github.com/Aghajari/JSSoup#readme","keywords":["jssoup","htmlparser","dom","html"],"repository":{"type":"git","url":"git+https://github.com/Aghajari/JSSoup.git"},"author":{"name":"AmirHossein Aghajari"},"bugs":{"url":"https://github.com/Aghajari/JSSoup/issues"},"license":"Apache-2.0","readme":"# JSSoup\n **JSSoup** is a fast and reliable HTML DOM parser library for JavaScript, node.js based on [PHP: simplehtmldom](https://github.com/simplehtmldom/simplehtmldom) and [Java: Jsoup](https://github.com/jhy/jsoup)\n\n[![Join the chat at https://gitter.im/Aghajari/community](https://badges.gitter.im/Aghajari/community.svg)](https://gitter.im/Aghajari/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\n- Works with well-formed and broken HTML documents.\n- Loads webpages and document strings.\n- Supports CSS selectors.\n\n# Usage\n\n### Installation\n```console\nnpm i @aghajari/jssoup\n```\n\n```js\nconst jssoup = require('@aghajari/jssoup');\n```\n\nLet's fetch music lyrics from [Google](https://www.google.com/search?q=Hello+lyrics) :\n```js\nconst doc = await jssoup.loadFromURL(\"https://www.google.com/search?q=Hello+lyrics\", options())\n\nconsole.log('track: ' + doc.getElementByAttr(\"data-attrid\", `\"title\"`).plainText())\nconsole.log('artist' + doc.getElementByAttr(\"data-attrid\", `\"subtitle\"`).plainText())\nconsole.log('lyrics' + doc.getElementByAttr(\"data-lyricid\").plainText())\n```\nOutput:\n```html\ntrack: Hello\nartist: Adele\nlyrics: Hello, it's me \nI was wondering if after all these years you'd like to meet \nTo go over everything \nThey say that time's supposed to heal ya...\n```\n\nFor finding the correct css selector for an specific element, you can use `HTMLNode.cssSelector()`,\n- `cssSelector()`: Get a CSS selector that will uniquely select this element\n\nJust try one example as a test and get the cssSelector for all.\n\n```js\nconst doc = await jssoup.loadFromURL(\"https://www.google.com/search?q=someone+like+you+lyrics\", options())\nconsole.log(doc.matchesPlainText('Someone Like You')[0].cssSelector())\n```\nYou will get `h2[data-attrid=title]` as the cssSelector, Now use this selector for all lyrics pages from Google.\n```js\nconst doc = await jssoup.loadFromURL(\"https://www.google.com/search?q=million+years+ago+lyrics\", options())\nconsole.log(doc.findFirst('h2[data-attrid=title]').plainText()) // Output: Million Years Ago\n```\n\n- Let's try parsing document string :\n```js\nconst html = `<html><head><title><b>JSSoup</b> - node.js</title></head></html>`\nconst title = jssoup.load(html).getElementByTagName('title') // or .findFirst('title');\nconsole.log(title.plainText()) // JSSoup - node.js\nconsole.log(title.innerText()) // <b>JSSoup</b> - node.js\nconsole.log(title.outerText()) // <title><b>JSSoup</b> - node.js</title>\n```\nBy the way, you can also use `const title = jssoup.load(html).titleEl()` for getting title.\n\n- Let's use id for finding the element.\n```js\nconst html = `<html><head><test id='element_id'>This is a test</test></head></html>`\nconst element = jssoup.load(html).getElementById('element_id') // or .findFirst('#element_id')\nconsole.log(element) // This is a test\n```\n\n- Let's use className for finding the element.\n```js\nconst html = `<html><head><test class='test header'>This is a test</test></head></html>`\nconst element = jssoup.load(html).getElementByClassName('test') // or .findFirst('.header')\nconsole.log(element) // This is a test\n```\n\n- Let's use attribute for finding the element.\n```js\nconst html = `<html><head><test data-type='test'>This is a test</test></head></html>`;\nconst element = jssoup.load(html).getElementByAttr('data-type'); // or .findFirst('[data-type]');\nconsole.log(element); // This is a test\n```\n\n- Other ways to get the same element :\n```js\nconst html = `<html><head><test class='tcls header' id='#element_id' data-type='test_attr'>This is a test</test></head></html>`\nconst doc = jssoup.load(html)\nelement = doc.getElementByTagName('test')\nelement = doc.findFirst('test')\nelement = doc.getElementByClass('tcls header')\nelement = doc.findFirst('test.tcls.header')\nelement = doc.getElementById('element_id')\nelement = doc.findFirst('test#element_id')\nelement = doc.getElementByAttr('data-type', 'test_attr')\nelement = doc.findFirst('test[data-type=test_attr]')\nelement = doc.findFirst('html > head > test:nth-child(0)')\n```\n\n- Get comments :\n```js\nconst html = `<html>\n<body>\n    <h1>This is a test</h1>\n    <!-- this is a comment -->\n</body>\n</html>`;\n\nconst doc = jssoup.load(html)\nconsole.log(doc.comments()[0]) // this is a comment\n```\n\n- Get metta tags :\n```js\nconst doc = await jssoup.loadFromURL(\"https://github.com/Aghajari\", options())\n\nconsole.log(doc.metaTags()) // Array of meta tags\nconsole.log(doc.metaEl('description')) // meta element for description\nconsole.log(doc.metaEl('image')) // meta content for image\n/*\n* metaEl() will search following tags:\n* <meta name=\"NAME\" content=\"bla bla\"> (Standard)\n* <meta property=\"og:NAME\" content=\"bla bla\">\n* <meta itemprop=\"NAME\" content=\"bla bla\">\n* <meta name=\"…NAME…\" content=\"bla bla\">\n* <meta property=\"…NAME…\" content=\"bla bla\">\n* <meta itemprop=\"…NAME…\" content=\"bla bla\">\n*/ \n```\n\n- LinkPreview inspired by [linkpreview](https://github.com/meyt/linkpreview) :\n```js\nconst doc = await jssoup.loadFromURL(\"https://github.com/Aghajari\", options())\n\nconsole.log('title', doc.title()) // Aghajari - Overview\nconsole.log('description', doc.description()) // Aghajari has ? repositories available. Follow their code on GitHub.\nconsole.log('image', doc.image()) // https://avatars.githubusercontent.com/u/30867537?v=4?s=400\n```\n\n- Getting multiple tags :\n```js\nconst html = `<html>\n<body>\n<tag1> This is test1 </tag1>\n<tag2> This is test2 </tag2>\n<tag3> This is test3 </tag3>\n</body>\n</html>`;\n\nconst doc = jssoup.load(html)\nconsole.log(doc.find(['tag1', 'tag2', 'tag3'])) // Array of elements\n```\n\n- Limit output indexes :\n```js\nconst html = `<html>\n<body>\n<tag> This is test0 </tag>\n<tag> This is test1 </tag>\n<tag> This is test2 </tag>\n<tag> This is test3 </tag>\n<tag> This is test4 </tag>\n<tag> This is test5 </tag>\n</body>\n</html>`;\n\nconst doc = jssoup.load(html)\nconsole.log(doc.find('tag', [2, -2])) // Array of elements (test2, test4)\n```\n\n- Get attribute from element:\n```js\nconst html = `<html><head><test data-id='id1234'>This is a test</test></head></html>`;\nconst element = jssoup.load(html).getElementByAttr('data-id'); // or .findFirst('test[data-id]');\nconsole.log(element.getAttribute('data-id')); // id1234\n```\n\n## Attribute Expression\n- `=` : equal `[attr=value]`\n- `!=` : unequal `[attr!=value]`\n- `*=` : regex `[attr*=value]`\n- `^=` : regex /^pattern/ `[attr^=value]`\n- `$=` : regex /pattern$/ `[attr$=value]`\n- `|=` : startsWith `[attr|=value]`\n- `&=` : endsWith `[attr&=value]`\n- `%=` : contains `[attr%=value]`\n- `~=` : contains in list of words `[attr~=value]`<br>`<tag attr='blue red green'>` : `[attr~=red]`\n\n## Author \n- **Amir Hossein Aghajari**\n\nLicense\n=======\n\n    Copyright 2021 Amir Hossein Aghajari\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n\n<div align=\"center\">\n  <img width=\"64\" alt=\"LCoders | AmirHosseinAghajari\" src=\"https://user-images.githubusercontent.com/30867537/90538314-a0a79200-e193-11ea-8d90-0a3576e28a18.png\">\n  <br><a>Amir Hossein Aghajari</a> • <a href=\"mailto:amirhossein.aghajari.82@gmail.com\">Email</a> • <a href=\"https://github.com/Aghajari\">GitHub</a>\n</div>\n","readmeFilename":"README.md"}