Skip to content

Instantly share code, notes, and snippets.

@wintrdotcom
Last active September 7, 2020 12:35
Show Gist options
  • Save wintrdotcom/27c4281c50efbf70e6062de0eb69e45d to your computer and use it in GitHub Desktop.
Save wintrdotcom/27c4281c50efbf70e6062de0eb69e45d to your computer and use it in GitHub Desktop.
Scrape Amazon product details, get a free WINTR API key on https://www.wintr.com
const WINTR_API_KEY = "your_wintr_api_key"
const TARGET_URL = "https://www.amazon.com/dp/B07ZDJCL76"
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": {
"details": {
"group": "html",
"data": {
"name": {
"selector": "title",
"attr": "*text*",
"replacer": [
{
"search": "Amazon.com:",
"replace": ""
}
],
"modifier": [
"totrimmed"
]
},
"rating": {
"selector": "#centerCol #acrPopover",
"attr": "title",
"modifier": [
"totrimmed"
]
},
"price": {
"selector": "#price_inside_buybox",
"attr": "*text*",
"replacer": [
{
"search": "\n",
"replace": ""
}
],
"modifier": [
"totrimmed"
]
},
"thumbnail_base64": {
"selector": "#main-image-container img:first-child",
"attr": "src",
"replacer": [
{
"search": "\n",
"replace": ""
}
],
"modifier": [
"totrimmed"
]
},
"description": {
"selector": "meta[name=\"description\"]",
"attr": "content",
"modifier": [
"totrimmed"
]
},
"long_description": {
"selector": "#productDescription p",
"attr": "*text*",
"replacer": [
{
"search": "\n",
"replace": ""
}
],
"modifier": [
"totrimmed"
]
},
"attribute_names": {
"selector": "#productDetails_detailBullets_sections1 th",
"attr": "*text*",
"replacer": [
{
"search": "\n",
"replace": ""
}
],
"modifier": [
"totrimmed"
]
},
"attribute_values": {
"selector": "#productDetails_detailBullets_sections1 td",
"attr": "*text*",
"replacer": [
{
"search": "\n",
"replace": ""
}
],
"modifier": [
"totrimmed"
]
},
"link": {
"selector": "link[rel=\"canonical\"]",
"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