Git Product home page Git Product logo

scrapehook's Introduction

ScrapeHook

Usage

const Hook = require('scrapehook')

Hook.observe('https://domain.com')

// No changes detected
Hook.on('nodiff', () => {
  // Do something
})

// Changes detected
Hook.on('update', (data) => {
  // Do something
  data.new // New content
  data.old // Old content
})

Options

Hook.observe('https://domain.com', {
  // The URL you want to POST the data
  postUrl: 'https://domain.com/post',
  // The element you want to watch
  // NOTE: `content` is a placeholder for the content you want to watch (it is required)
  element: '<title>content</title>',
  // At which interval you want to scrape ? Default: 5 minutes
  interval: 10*60*1000 // Scrape every 10 minutes
})

API

.observe(url[, options])

url: String (The URL you want to observe)
options: Object
  • postUrl String (Send a POST request to postUrl with data as a payload)
  • element: String (The element you want to watch)
  • interval: Number Default: 5 minutes
ScrapeHook.observe('https://domain.com', {
  postUrl: 'https://domain.com/post' // It will send a POST request to this URL which contains old & new data
})

The POST request

{
  "new": "New data",
  "old": "Old data"
}

If you want to watch the title of a page for example : Note that content will be replaced by the actual content of the web page.

Hook.observe('https://domain.com', {
  element: '<h1>content</h1>'
})

Change the interval

Hook.observe('https://domain.com', {
  interval: 60*60*1000 // It will scrape every 1 hour
})

Events

nodiff

Event 'nodiff' is emitted when a website does not change

Hook.on('nodiff', () => {
  console.log('Same content !')
})

update

Event 'update' is emitted when a website change

  • data.new contains the new content
  • data.old contains the old content
Hook.on('update', (data) => {
  console.log(data.new) // 'new content'
  console.log(data.old) // 'old content'
})

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.