Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
package-lock.json
package-lock.json
.yalc
yalc.lock
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

[![NPM License](https://img.shields.io/npm/l/all-contributors.svg?style=flat)](https://github.com/exoticchild-alt/pastebin-scraper/blob/master/LICENSE)
[![NPM Downloads](https://img.shields.io/npm/dt/pastebin-scraper.svg?style=flat)]()
[![NPM](https://nodei.co/npm/pastebin-scraper.png?downloads=true)](https://www.npmjs.com/pastebin-scraper)
[![NPM](https://nodei.co/npm/pastebin-scraper.png?downloads=true)](https://www.npmjs.com/pastebin-scraper)
<br>
[![GitHub Release](https://img.shields.io/github/release/exoticchild-alt/pastebin-scraper.svg?style=flat)]()
[![GitHub Release](https://img.shields.io/github/release/exoticchild-alt/pastebin-scraper.svg?style=flat)]()
[![Issues](https://img.shields.io/github/issues-raw/exoticchild-alt/pastebin-scraper.svg?maxAge=25000)](https://github.com/exoticchild-alt/pastebin-scraper/issues)
[![run on repl.it](https://repl.it/badge/github/exoticchild-alt/pastebin-scraper)](https://repl.it/github/exoticchild-alt/pastebin-scraper)
[![Open Source](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://opensource.org/)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)

### *Usage* ###
First, to be able to use the library, install it first using the following command
First, to be able to use the library, install it first using the following command:
```bash
npm install pastebin-scraper --save
```
$ npm install pastebin-scraper --save
```
This library is a promise-based library, so you first must require it in your code and then use it somewhat like this.

This library is a promise-based library, so you first must require it in your code and then import the function `Scrape`:
```javascript
const scrape = require('pastebin-scraper')
scrape('https://pastebin.com/4Z489JeC')
const {Scrape} = require('pastebin-scraper');
Scrape('https://pastebin.com/4Z489JeC')
.then(res => console.log(res))
//response looks something like this
```

/*
Output will be an object, which can be accessed using properties.
```bash
{
title: 'Pastebin Scraper',
views: '8',
Expand All @@ -32,8 +34,8 @@ scrape('https://pastebin.com/4Z489JeC')
dateCreated: 'Aug 15th, 2021',
language: 'text'
}
*/
```
You can run this test this library in the tryit.js folder if you are, for example, running this library in Github or Replit.

You can run this test this library in the tryit.js folder if you are, for example, running this library in GitHub or Replit.
<br>
*v1.0.1*
*v2.0.0*
9 changes: 9 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export declare function Scrape(url: string): Promise<{
title: string;
views: string;
rawData: string;
user: string;
expiration: string;
dateCreated: string;
language: string;
}>;
30 changes: 30 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Scrape = void 0;
const cheerio = require("cheerio");
const axios = require('axios').default;
function Scrape(url) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield axios.get(url);
const $ = cheerio.load(response.data);
return {
title: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-top > h1").text(),
views: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.visits").text().replace("\n", "").trim(),
rawData: $("body > div.wrap > div.container > div.content > div.post-view > textarea").text(),
user: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.username > a").text(),
expiration: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.expire").text().replace("\n", "").trim(),
dateCreated: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.date > span").text(),
language: $("body > div.wrap > div.container > div.content > div.post-view > div.highlighted-code > div.top-buttons > div.left > a").text()
};
});
}
exports.Scrape = Scrape;
10 changes: 5 additions & 5 deletions index.js → lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const cheerio = require('cheerio');
const axios = require('axios');
module.exports = async function(url) {
import cheerio = require('cheerio');
const axios = require('axios').default;
export async function Scrape(url: string) {
const response = await axios.get(url);
const $ = cheerio.load(response.data);
return {
title: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-top > h1").text(),
views: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.visits").text().replace("\n", "").trim(),
views: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.visits").text().replace("\n", "").trim(),
rawData: $("body > div.wrap > div.container > div.content > div.post-view > textarea").text(),
user: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.username > a").text(),
expiration: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.expire").text().replace("\n", "").trim(),
dateCreated: $("body > div.wrap > div.container > div.content > div.post-view > div.details > div.info-bar > div.info-bottom > div.date > span").text(),
language: $("body > div.wrap > div.container > div.content > div.post-view > div.highlighted-code > div.top-buttons > div.left > a").text()
}
}
}
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
{
"name": "pastebin-scraper",
"version": "1.0.1",
"version": "2.0.0",
"description": "A simple library that scrapes data about pastes from Pastebin",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"prepublish": "npm run build",
"pretest": "yalc publish && yalc add pastebin-scraper",
"test": "node tryit.js",
"tsc-init": " cd node_modules/.bin/ && tsc --init",
"build": "tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/exoticchild-alt/pastebin-scraper.git"
},
"keywords": ["pastebin", "scraper", "web", "cheerio", "axios"],
"author": "",
"author": "https://github.com/exoticchild",
"license": "MIT",
"bugs": {
"url": "https://github.com/exoticchild-alt/pastebin-scraper/issues"
},
"homepage": "https://github.com/exoticchild-alt/pastebin-scraper#readme",
"dependencies": {
"axios": "^0.21.1",
"axios": "^0.24.0",
"cheerio": "^1.0.0-rc.10"
},
"devDependencies": {
"@types/node": "^16.11.7",
"typescript": "^4.4.4",
"yalc": "^1.0.0-pre.53"
}
}
9 changes: 6 additions & 3 deletions tryit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//here you can try this library
//const pastebin = require('pastebin-scraper')
const scrape = require('pastebin-scraper')
scrape('https://pastebin.com/4Z489JeC').then(res => console.log(res))
//const {scrape} = require('pastebin-scraper')
const {Scrape} = require('pastebin-scraper');
const res = Scrape('https://pastebin.com/4Z489JeC')
.then(res => console.log(res));
//console.log(res);
console.log(typeof res);
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"strict": true,
"moduleResolution": "node"
}
}