Last active
March 11, 2021 12:59
-
-
Save wintrdotcom/4f93750b25d06f7558fc180f83118c8c to your computer and use it in GitHub Desktop.
Scrape Craiglist listing 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://losangeles.craigslist.org/search/sss?query=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) | |
"proxytype": "residential", | |
"headers": { | |
"Accept-Language": "en-US,en;q=0.9,es;q=0.8", | |
"Referer": "https://www.google.com" | |
}, | |
"outputschema": { | |
"list": { | |
"group": ".result-row", | |
"data": { | |
"name": { | |
"selector": "a.result-title", | |
"attr": "*text*", | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"price": { | |
"selector": ".result-meta .result-price", | |
"attr": "*text*", | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"thumbnail": { | |
"selector": ".swipe img:first-child", | |
"attr": "src", | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"location": { | |
"selector": ".result-hood", | |
"attr": "*text*", | |
"replacer": [ | |
{ | |
"search": "(", | |
"replace": "" | |
}, | |
{ | |
"search": ")", | |
"replace": "" | |
} | |
], | |
"modifier": [ | |
"totrimmed" | |
] | |
}, | |
"link": { | |
"selector": "a.result-title", | |
"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