Socket
Socket
Sign inDemoInstall

scraper-api

Package Overview
Dependencies
24
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    scraper-api

Interface for calling ScraperAPI from Node


Version published
Weekly downloads
12
Maintainers
1
Created
Weekly downloads
 

Readme

Source

scraper-api

npm npm David Travis Coveralls license Beerpay

Interface to call ScraperAPI.com easily from Node. All current API endpoints and features are implemented in this module. Requires Node 8+.

Install

$ npm install --save scraper-api

Usage

const scraperAPI = require('scraper-api')({
    // ... options
});

scraperAPI.get('http://httpbin.org/ip')
    .then(result => {
        // result => '<!doctype html> ...'
    })
    .catch(error => {
        console.error(error);
        //=> 'Internal server error'
    });

API Documentation

scraper-api

scraperAPI(options) ⇒ ScraperAPI

Creates new instance of ScraperAPI with the provided options.

Kind: Exported function
Returns: ScraperAPI - New instance of ScraperAPI.

ParamTypeDefaultDescription
optionsObjectOptional configuration options to pass into ScraperAPI.
[options.apiKey]Stringprocess.env.SCRAPER_API_KEYAPI key for Scraper API. Defaults to pulling API Key from environment variable.
[options.renderJs]BooleanfalseRender JavaScript on the page before scraping the HTML for the page.
[options.keepHeaders]BooleanfalseKeep headers sent in the request to Scraper API in subsequent request(s) when scraping the provided url. You must set your headers in options.gotOptions.headers.
[options.geoCode]String'us'Geo code in which to use proxies for when scraping. See documentation for more information.
[options.premium]BooleanfalseWhether to use premium proxies. Caution: This will cost 10-25 times more than standard proxies.
[options.sessionId]NumberA numeric session id to use to maintain the same proxy. See ScraperAPI.session() for more information.
[options.gotOptions]Object{}Additional options to pass into got for requests to ScraperAPI.

Example

const scraperAPI = require('scraper-api')({
    // options...
});

scraperAPI.ScraperAPI

Access to the uninstantiated ScraperAPI class.

Kind: static property of scraperAPI
Example

const ScraperAPI = require('scraper-api').ScraperAPI;
const scraperAPI = new ScraperAPI({
    // options...
});

ScraperAPI

Kind: global class

new ScraperAPI([options])

Constructor for the ScraperAPI class.

ParamTypeDefaultDescription
[options]Object{}Options for the ScraperAPI class. Options may be overridden on all methods for a single request. See options above for more information.

scraperAPI.session(id, [options]) ⇒ ScraperAPI

Creates a new instance of ScraperAPI with the specified session id. Sessions allow subsequent requests with the same session id to go through the same proxy. See documentation for more information.

Kind: instance method of ScraperAPI
Returns: ScraperAPI - A new instance of ScraperAPI with sessionId set to the provided id.

ParamTypeDefaultDescription
idNumberSession ID in which to use for the given session. Must only contain numbers.
[options]Object{}Options to override for all subsequent requests to Scraper API. Same as the global options.

Example

const session = scraperAPI.session(1234);

let result = await scraperAPI.get('https://google.com');
// result -> '<!doctype html> ...'

scraperAPI.get(url, [options]) ⇒ Promise.<String>

Calls Scraper API with a GET request to the provided url.

Kind: instance method of ScraperAPI
Returns: Promise.<String> - Promise that resolves with HTML source from requested URL.

ParamTypeDefaultDescription
urlStringThe URL in which to scrape.
[options]Object{}Options to override for this specific request.

Example

let result = await scraperAPI.get('https://google.com');
// result -> '<!doctype html> ...'

scraperAPI.post(url, data, [options]) ⇒ Promise.<Object>

Calls Scraper API with a POST request to the provided url with the provided data.

Kind: instance method of ScraperAPI
Returns: Promise.<Object> - Promise that resolves with object response from Scraper API. See documentation.

ParamTypeDefaultDescription
urlStringThe URL in which to scrape.
dataObject | form-dataData in which to post to the provided URL. Must be either a plain object or instance of form-data.
[options]Object{}Options to override for this specific request. May be any of the global options and any additional options below.
[options.form]BooleanfalseSet true if provided data is form data and should be sent as such. By default, data will be sent as JSON.

Example

let result = await scraperAPI.post('https://example.com/endpoint', {
   hello: 'world',
   some: 'data'
});

More Information

keepHeaders Option

If you would like to pass custom headers through Scraper API to the destination, you may do so by setting your custom headers in options.gotOptions.headers and enabling this option.

let result = await scraperAPI.get('https://google.com', {
    keepHeaders: true,
    gotOptions: {
        headers: {
            'My-Custom-Header': 'some value'
        }
    }
});

Tests

Tests are written and provided as part of the module. You may run the tests by calling:

$ npm run test

License

MIT License. See License in the repository.

Keywords

FAQs

Last updated on 14 Aug 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc