Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kyle-n/unofficial-amazon-search

A simple client for searching Amazon
https://github.com/kyle-n/unofficial-amazon-search

amazon amazon-search javascript nodejs scraper scraping typescript web

Last synced: 2 months ago
JSON representation

A simple client for searching Amazon

Awesome Lists containing this project

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`.

```typescript
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 `` 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.

```html
<!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">

var searchAmazon = window.UnofficialAmazonSearch.searchAmazon;
searchAmazon('123').then(function (data) {
console.log(data.searchResults);
});