Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created April 9, 2020 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattlockyer/2bc060474ab7f057efb17b5de3ec0a91 to your computer and use it in GitHub Desktop.
Save mattlockyer/2bc060474ab7f057efb17b5de3ec0a91 to your computer and use it in GitHub Desktop.
Scrapes Ebay Prices
const cheerio = require('cheerio')
const request = require('request');
let query = process.env.QUERY
if (!query) {
console.log('Please define an ENV var for QUERY="..."')
return -1
}
query = encodeURIComponent(query)
console.log(query)
const url = `https://www.ebay.com/sch/i.html?_from=R40&_trksid=p2380057.m570.l1313.TR12.TRC2.A0.H0.X${query}.TRS0&_nkw=${query}&_sacat=0`
request(url, function (error, response, body) {
// console.error('error:', error); // Print the error if one occurred
// console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
// console.log('body:', body); // Print the HTML for the Google homepage.
const $ = cheerio.load(body)
const data = []
const prices = $('li .s-item__price')
const titles = $('li .s-item__title')
titles.each(function(i, el) {
data.push({
title: $(this).text(),
price: $(prices[i]).text()
})
})
console.log(data)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment