Reputation: 33
I'm trying to use request-promise to scrape a the price of an item from Asos.com. When I attempt to run the code below, I get a 403 error. Is this possible that I get this error although the URL that I am attempting to scrape is publicly available, no key required?
I know some site are against scraping in their ToS but I just want to be sure I am not just performing this wrong or if I am actually getting blocked by the site.
const rp = require('request-promise');
var url = 'http://www.asos.com/api/product/catalogue/v2/stockprice?productIds=10000496¤cy=SEK&keyStoreDataversion=7jhdf34h-6&store=ROE';
rp({ url:url, json:true })
.then(function (data) {
console.log(data.productPrice.current.value);
})
.catch(function (reason) {
console.error("%s; %s", reason.error.message, reason.options.url);
console.log("%j", reason.response.statusCode);
});
Upvotes: 2
Views: 3470
Reputation: 167
You should add "headers" parameter, i.e.:
rp({
url:url,
headers: {
'User-Agent': 'Request-Promise'
},
json:true
})
Upvotes: 4