1.0.1 • Published 9 years ago
hmv-scraper v1.0.1
hmv-scraper
Scraper that searches products on the Canadian HMV store hmv.ca.
install
Using npm.
npm install hmv-scraper
usage
new HmvScraper(onProductError)
Optional param onProductError is a function that will be called when a product unexpectedly fail the validation. It takes respectively, the product, an array of AJV Error, and a string that represents the errors.
var HmvScraper = require('hmv-scraper');
var onProductError = function (product, errors, errorsText) {
console.log('Product failed validation: ' + errorsText);
console.log(product);
};
var hmv = new HmvScraper(onProductError);
// or
var HmvScraper = require('hmv-scraper');
var hmv = new HmvScraper();
searchByKeyword(query, callback(error, results))
Search products by keyword.
hmv.searchByKeyword({
query: 'James Bond'
}, function(error, results) {
if (error) {
console.log(error);
} else {
console.log(results);
}
});
searchByArtist(query, callback(error, results))
Search products by artist.
hmv.searchByArtist({
query: 'Céline Dion',
sort: 'Bestselling',
filter: 'All',
page: 3
}, function(error, results) {
if (error) {
console.log(error);
} else {
console.log(results);
}
});
param query
Name | Description | Accepted values | Default value | Required |
---|---|---|---|---|
query | The keyword or the artist you search. | String | Yes | |
page | The page of result that you want. | Integer | 1 | No |
filter | The group in which you want to search. | 'All', 'CD', 'Vinyl', 'DVD', 'Bluray', '3dBluray', 'Headphones', 'GiftsCollect', 'Apparel' | 'All' | No |
sort | The order in which the products should sort. | 'Bestselling', 'Date of release', 'Price: Low to High', 'Price: High to Low', 'Alphabetical: A to Z', 'Alphabetical: Z to A' | 'Bestselling' | No |
param callback(error, products)
Function that is called when the request is done or when there is an error.
product
The structure of a product is described below, for more details check the product JSON schema.
Name | Type | Description | Always present |
---|---|---|---|
id | Integer | Id | Yes |
sku | Integer | SKU | Yes |
name | String | Name of the product | Yes |
priceInCents | Integer | Price in cents in Canadian dollar | Yes |
category | String | The category ('Music', 'Film', 'Apparel', 'Headphones', 'Gift') | Yes |
kind | String | The kind of product or its format if the category is 'Music' or 'Film' | Yes |
available | Boolean | If the product is available online | Yes |
url | String | Url of the product in the store | Yes |
reservationUrl | String | The reservation URL to find a store and reserve the product | Yes |
catalogue | String | Catalogue number or serial number | No |
promotion | String | The promotions | No |
supplier | String | The supplier name | No |
smallImageUrl | String | Small image URL | No |
mediumImageUrl | String | Medium image URL | No |
largeImageUrl | String | Large image URL | No |
releaseDate | String | The released date in ISO 8601 date format | Only if category is 'Music' or 'Film' |
artist | String | The artist of the product | Only if category is 'Music' |
Example:
{
id: 72201,
sku: 246337,
name: 'NEW DAY HAS COME',
priceInCents: 1500,
category: 'Music',
kind: 'CD',
available: true,
url: 'https://www.hmv.ca/en/Search/Details?sku=246337',
reservationUrl: 'https://www.hmv.ca/en/Stores?reserve=true&id=72201',
catalogue: 'CK86400',
supplier: 'COLUMBIA',
smallImageUrl: 'https://www.hmv.ca/images/Music/75/44/4443/444344.jpg',
mediumImageUrl: 'https://www.hmv.ca/images/Music/170/44/4443/444344.jpg',
largeImageUrl: 'https://www.hmv.ca/images/Music/450/44/4443/444344.jpg',
artist: 'CELINE DION',
releaseDate: '2002-03-26'
}
Contributing
Contribution is welcome! Open an issue first.
test
npm test
license
MIT