npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-pastebin-scraper

v1.0.2

Published

A rudimentary way to scrape recent pastes on pastebin without having an API key.

Downloads

6

Readme

Node Pastebin Scraper

Setup

Install

Install dependencies

npm i node-pastebin-scraper

Build

Build the files, the output will be in the folder dist. You can import dist/index.js for non ES6 class compatible enviroments.

npm run build

Use example.js

You need nodemon for this.

npm i -g nodemon

Run the example as in example.js

npm run example

Usage: Basic

You can define an array of regex expressions to be matched to each paste's body, the scraper will run through the most recent posted 'pastes' on PasteBin once.

import PasteBinScraper from './src/index';

//wait 5 seconds before scanning the next paste (default time - recommended).
const scraper = new PasteBinScraper({ eachPasteWait: 5000 });


const expressions = [/password/i, / dump /i, /hotmail/i, /gmail/i, /yahoo/i, /hack/i, /leak/i, /db_pass/i, /db_password/i, /href/i, /class/i];

scraper.setExpressionsToMatch(expressions);

scraper.scrape()
    .then(()=>console.log('Finished Scraping recent pastes!'))
    .catch((e)=>console.error(e));

scraper.on('match',(paste)=>{
    console.log(`Matched paste! URL (${paste.url} , posted: ${paste.timePosted}`)
})

Usage: Poll Recent Pastes Continously

scraper.Repeat() exposes (https://www.npmjs.com/package/repeat) a Repeat object, which will scrape PasteBin as per it's configuration.

Note: Repeat is not being maintained anymore, so not recommended for Production use cases.

import PasteBinScraper from './src/index';

const scraper = new PasteBinScraper();


const expressions = [/password/i, / dump /i, /hotmail/i, /gmail/i, /yahoo/i, /hack/i, /leak/i, /db_pass/i, /db_password/i, /href/i, /class/i];

scraper.setExpressionsToMatch(expressions);

// under 3 minutes not recommended
scraper.Repeat().every(3, 'minutes').for(120, 'minutes');

scraper.on('match',(paste)=>{
    console.log(`Matched paste! URL (${paste.url} , posted: ${paste.timePosted}`)
})

API

constructor(ConfigurationObject)

ConfigurationObject.eachPasteWait

The only available configuration at this time is how long to wait before scanning the next paste.

const scraper = new PasteBinScraper({ eachPasteWait: 5000 });

scrape()

Starts scraping process, that is, look at Pastebin's recent pastes and iterate through each of them then emit the event match when the match condition is met.

Returns a promise that is resolved when the list of recent pastes has been iterated.

scraper.scrape();

setMatchCondition(Function)

You can customize what condition should be met when iterating through each paste by supplying a handler, the object 'paste' is passed which contains the attributes: url, postedTime, body

By default the match condition is just iterates through a set of regex expressions (set by setExpressionsToMatch) to ensure at least there is one match, before emitting the 'match' event.

// This example replaces the match condition for all scraping purposes

// If any paste satisfies this condition, 'match' will be emitted.

const handler = (paste)=>{
    let { url, postedTime, body } = paste;
    return body.match(/database/i)
}
scraper.setMatchCondition(handler);

setExpressionsToMatch(Array)

Sets an array of Regular Expressions that will need to be matched with a paste's body, assuming setMatchCondition has not been called (i.e the default match condition has not been replaced).

scraper.setExpressionsToMatch([/(password|pass)/i,/dralejandro/i]);

Repeat()

Exposes (https://www.npmjs.com/package/repeat) a Repeat object, which will scrape PasteBin as per it's configuration.

scraper.Repeat().every(3, 'minutes').for(120, 'minutes');

on(EventString, Handler)

EventString: 'match'

This event is passed a paste object which contains the attributes: url, postedTime, body;

 scraper.on('match',(paste)=>{
     //do something
 })