unofficial-amazon-search
v2.0.8
Published
A simple client for searching Amazon
Downloads
52
Maintainers
Readme
unofficial-amazon-search
A simple client for searching Amazon
Install
npm install unofficial-amazon-search
or
yarn add unofficial-amazon-search
How to use
searchAmazon
returns Promise<SearchData>
.
import {searchAmazon, AmazonSearchResult} from 'unofficial-amazon-search';
// OR
const {searchAmazon, AmazonSearchResult} = require('unofficial-amazon-search');
searchAmazon('anything you would put in the search bar').then(data => {
console.log(data);
console.log(data.pageNumber) // 1
console.log(data.searchResults[0].title, data.searchResults[0].imageUrl);
});
// load other pages by specifying a page number
// or calling getNextPage()
searchAmazon('mad max', {page: 2, includeSponsoredResults: true}).then(data => {
console.log(data.pageNumber) // 2
console.log(data.searchResults) // (page 2 results)
return data.getNextPage();
}).then(data => {
console.log(data.searchResults) // (page 3 results)
});
The above works in Node and frontend environments with compiled code.
unofficial-amazon-search
can also be imported from a <script>
tag and used in raw JS. Importing it will attach the
module to the window
object. Browser queries are proxied through AllOrigins.win, a limit-free proxy, to avoid CORS issues.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My beautiful webpage</title>
<meta charset="UTF-8">
</head>
<body></body>
<script src="path/to/unofficial-amazon-search/_bundles/unofficial-amazon-search.min.js" rel="script"></script>
<script>
var searchAmazon = window.UnofficialAmazonSearch.searchAmazon;
searchAmazon('123').then(function (data) {
console.log(data.searchResults);
});
</script>
</html>
The bundle contains minified and non-minified bundles of the compiled search code.
This is a Promise-based API and does not support callbacks, so you will have to roll your own solution for Internet Explorer.
API
Function searchAmazon
Parameters:
query
- string that you'd put into the Amazon website search barconfig
- optional object, can specify any (or none) of the properties onSearchConfig
.
Returns a Promise<SearchData>
.
Interface SearchConfig
page
- desired page of resultsincludeSponsoredResults
- settrue
to include ads
Interface SearchData
An object with properties:
searchResults
-Array<AmazonSearchResult>
pageNumber
- Page number of current set ofsearchResults
getNextPage
- If there is another page of results for the given query, this function returns a Promise for that next page. If there is no next page, this is undefined.
Class AmazonSearchResult
imageUrl
- lead product image that shows in search resultstitle
- name of productproductUrl
- URL for product details pagerating
- x out of y possible score (e.x. 4.2 out of 5)prices
- Search often lists multiple prices for versions of an item. This is a set of all found prices, some of which have labels attached (for example, if you search a DVD barcode number, there are multiple prices, for DVD, Blu-ray and 4K, and each has a label like "4K"). Price label is null if cannot find it on pagesponsored
- whether result is an ad.searchAmazon
filters out these by default