Package Exports
- price-finder
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (price-finder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
price-finder
The price-finder module helps find the price of retail items online. It does this by taking in a URI for a webpage that displays the product information, and scrapes the page to find the price (optionally able to find the name and category of products as well).
Quick Examples
Find an item's current price online
var priceFinder = require("price-finder");
// Atoms for Peace : Amok (from Amazon)
var uri = "http://www.amazon.com/Amok/dp/B00BIQ1EL4";
priceFinder.findItemPrice(uri, function(err, price) {
console.log(price); // 8.91
});
// Ferris Bueller's Day Off (from BestBuy)
uri = "http://www.bestbuy.com/site/ferris-buellers-day-off-dvd/7444513.p?id=47476&skuId=7444513";
priceFinder.findItemPrice(uri, function(err, price) {
console.log(price); // 3.99
});
Find additional details on an item, including price
var priceFinder = require("price-finder");
// Plants vs Zombies (from Google Play)
var uri = "https://play.google.com/store/apps/details?id=com.popcap.pvz_na";
priceFinder.findItemDetails(uri, function(err, itemDetails) {
console.log(itemDetails.price); // 0.99
console.log(itemDetails.name); // Plants vs. Zombies™
console.log(itemDetails.category); // Mobile Apps
});
// Blues Brothers (from Amazon)
uri = "http://www.amazon.com/Blues-Brothers-Blu-ray-John-Belushi/dp/B001AQO446";
priceFinder.findItemDetails(uri, function(err, itemDetails) {
console.log(itemDetails.price); // 13.01
console.log(itemDetails.name); // The Blues Brothers [Blu-ray] (1980)
console.log(itemDetails.category); // Movies & TV
});API
findItemPrice(uri, callback)
Given a uri (that is for a supported site), this
function will scrape the page and attempt to find the current price listed on the page,
sending it to the callback. The callback's arguments are:
error: If an error occurred during processing, this will contain the error information. If no errors occurred, this will benull.price: The current price of the item listed on the page (aNumber).
findItemDetails(uri, callback)
Given a uri (that is for a supported site), this
function will scrape the page and attempt to find the item details listed on the page,
sending it to the callback. The callback's arguments are:
error: If an error occurred during processing, this will contain the error information. If no errors occurred, this will benull.itemDetails: This object contains three things:price: The current price of the item listed on the page (aNumber).name: The name of the product (if supported by the site implementation).category: The category of the product (if supported by the site implementation).
Supported Sites
The current supported sites are:
- Amazon
- Google Play
- Best Buy
Don't see your site listed? Please consider contributing to the project!
Contributing
The price-finder project is a Node.js module, so before cloning the repository make sure node is installed. Once cloned, install dependencies by issuing:
npm install
Tests
The project uses Jasmine for tests (please add tests for any new features). To run the unit tests execute:
npm test
These tests can additionally be run once, while watching the files for any changes, and if that occurs, re-run the tests. To do so execute:
npm run test-watch
End-to-end tests exist which will test the price-finder module using real URIs, scraping the pages to verify the code works correctly. Note that these tests should be run on a limited basis while coding since some sites have been known to throw up CAPTCHA's after repeated, automated page requests. To execute these tests run:
npm run test-e2e
Adding Sites
This project was built to easily drop in support for new sites. The
site-manager iterates over all files contained within the
sites directory, and adds it to the list of available sites. When a
request is issued to price-finder to look up a price, it asks each site if the
uri is supported by the site, and if so, uses that site to find the
price (or name, category).
The site interface is:
function Site(uri) {
/**
* Returns the URI used to find the page data
* (most likely the same URI used in constructing this Site)
*
* @return {String} The URI used to find the page data
*/
function getURIForPageData();
/**
* Returns true if the page data is JSON
*
* @return {Boolean} true if the page data is JSON, false otherwise
*/
function isJSON();
/**
* Returns the price found on the page
*
* @param {Object} $ jQuery object used to search the page
* @return {String} The price found on the page
*/
function findPriceOnPage($);
/**
* Returns the category of the item found on the page
*
* @param {Object} $ jQuery object used to search the page
* @return {String} The category found on the page
*/
function findCategoryOnPage($);
/**
* Returns the name of the item found on the page
*
* @param {Object} $ jQuery object used to search the page
* @param {String} category The product's category
* @return {String} The category found on the page
*/
function findNameOnPage($, category);
}
/**
* Returns true if this site supports the incoming URI
*
* @param {String} uri The URI to test
* @return {Boolean} true if this Site supports the URI, false otherwise
*/
Site.isSite = function(uri);