Last active
September 7, 2020 12:35
-
-
Save wintrdotcom/a35b6d70921874c01f42f8f0605df77e to your computer and use it in GitHub Desktop.
Scrape Amazon product list, get a free WINTR API key on https://www.wintr.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const WINTR_API_KEY = "your_wintr_api_key" | |
const TARGET_URL = "https://www.amazon.com/s?k=phone" | |
const axios = require("axios") | |
const options = { | |
method: "post", | |
responseType: "json", | |
data: { | |
"apikey": WINTR_API_KEY, | |
"url": TARGET_URL, | |
"jsrender": true, // comment this to run the query faster (it might fail more often tho) | |
"renderuntil": "domloaded", // comment this to run the query faster (it might fail more often tho) | |
"headers": { | |
"Accept-Language": "en-US,en;q=0.9,es;q=0.8", | |
"Referer": "https://www.google.com" | |
}, | |
"outputschema": { | |
"list": { | |
"group": ".s-search-results [data-component-type=\"s-search-result\"]", | |
"data": { | |
"name": { | |
"selector": "h2:first-of-type a.a-link-normal", | |
"attr": "*text*", | |
"replacer": [ | |
{ | |
"search": "\n", | |
"replace": "" | |
} | |
], | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"rating": { | |
"selector": ".a-icon-star-small", | |
"attr": "*text*", | |
"replacer": [ | |
{ | |
"search": " out of 5 stars", | |
"replace": "" | |
} | |
], | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"price": { | |
"selector": ".a-price:not(.a-text-price) .a-offscreen", | |
"attr": "*text*", | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"thumbnail": { | |
"selector": ".s-image", | |
"attr": "src", | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"link": { | |
"selector": "h2:first-of-type a.a-link-normal", | |
"attr": "href", | |
"modifier": [ | |
"totrimmed" | |
] | |
} | |
} | |
} | |
} | |
}, | |
url: "https://api.wintr.com/fetch" | |
} | |
axios(options) | |
.then((result) => { | |
console.log(result.data.content) | |
}) | |
.catch((err) => { | |
console.error(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment