diff --git a/.eggignore b/.eggignore new file mode 100644 index 0000000..9dc001a --- /dev/null +++ b/.eggignore @@ -0,0 +1,12 @@ +.git*/** +.idea/** +.vscode/** +benchmarks/** +eggs-debug.log +.github +LICENSE +deno.json +.vscode +.gitignore +test.ts +score.ts \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6fb56b4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test Scrape + +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Setup Deno environment + uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + + - name: Setup Cache + uses: actions/cache@v3 + with: + path: | + ~/.deno + ~/.cache/deno + key: ${{ runner.os }}-deno-${{ hashFiles('**/_config.ts', '**/import_map.json') }} + + - name: Running Tools + run: | + deno run --allow-net --allow-read test.ts \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5986fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +_cache +eggs-debug.log +score.ts \ No newline at end of file diff --git a/.vscode/LICENSE b/.vscode/LICENSE new file mode 100644 index 0000000..7ecb9c9 --- /dev/null +++ b/.vscode/LICENSE @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2022 Santhosh Veer + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..27ec43b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "deno.enable": true, + "deno.lint": true, + "deno.unstable": true, + "deno.suggest.imports.hosts": { + "https://deno.land": true + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..4e9895c --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Deno Cheerio + +[![Test Scrape](https://github.com/mskian/deno-cheerio-js/actions/workflows/test.yml/badge.svg)](https://github.com/mskian/deno-cheerio-js/actions/workflows/test.yml) +![Deno](https://img.shields.io/badge/Deno-464647?style=for-the-badge&logo=deno&logoColor=white) + +Cheerio - Porting Cheerio Node Module To Deno using `esm.sh` + +## Prerequisites + +- Deno on your System + +## Usage + +- Cheerio Full Docs and usage - + +```js +import { cheerio } from "https://deno.land/x/denocheerio/mod.ts"; + +fetch( + "https://notes.santhoshveer.com/", +) + .then((result) => result.text()) + .then((html) => { + const $ = cheerio.load(html); + const title = $('meta[property="og:title"]').attr("content") || + $("title").text() || $('meta[name="title"]').attr("content"); + const description = $('meta[property="og:description"]').attr("content") || + $('meta[name="description"]').attr("content"); + console.log(title); + console.log(description); + }).catch((error) => { + console.log(error); + }); +``` + +## Testing + +```sh +deno run --allow-net --allow-read test.ts + +or + +deno task test +``` + +## Credits + +- cheerio Npm Module - + +## LICENSE + +MIT diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..46663e9 --- /dev/null +++ b/deno.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "test": "deno run --allow-net --allow-read test.ts" + } +} diff --git a/egg.json b/egg.json new file mode 100644 index 0000000..7e3bf02 --- /dev/null +++ b/egg.json @@ -0,0 +1,28 @@ +{ + "$schema": "https://x.nest.land/eggs@0.3.10/src/schema.json", + "name": "cheerio", + "entry": "./mod.ts", + "description": "Cheerio - Porting Cheerio Node Module To Deno", + "homepage": "https://github.com/mskian/deno-cheerio-js", + "version": "0.0.1", + "releaseType": null, + "unstable": false, + "unlisted": false, + "files": [ + "README.md" + ], + "ignore": [ + ".git", + ".github", + "LICENSE", + "deno.json", + ".vscode", + ".gitignore", + "test.ts", + "score.ts" + ], + "checkFormat": "deno fmt", + "checkTests": false, + "checkInstallation": false, + "check": true + } \ No newline at end of file diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..2a21bbc --- /dev/null +++ b/mod.ts @@ -0,0 +1,9 @@ +/** + * Deno Cheerio + * Cheerio - Porting Cheerio Node Module To Deno + * Convert using - https://esm.sh/ + */ + +import * as cheerio from "https://esm.sh/cheerio@1.0.0-rc.12"; + +export { cheerio }; diff --git a/test.ts b/test.ts new file mode 100644 index 0000000..8515725 --- /dev/null +++ b/test.ts @@ -0,0 +1,17 @@ +import { cheerio } from "./mod.ts"; + +fetch( + "https://notes.santhoshveer.com/", +) + .then((result) => result.text()) + .then((html) => { + const $ = cheerio.load(html); + const title = $('meta[property="og:title"]').attr("content") || + $("title").text() || $('meta[name="title"]').attr("content"); + const description = $('meta[property="og:description"]').attr("content") || + $('meta[name="description"]').attr("content"); + console.log(title); + console.log(description); + }).catch((error) => { + console.log(error); + });