Skip to content

Instantly share code, notes, and snippets.

@402332509
Created October 11, 2017 01:50
Show Gist options
  • Save 402332509/b4c32ec02196324b0328480d4b25e28b to your computer and use it in GitHub Desktop.
Save 402332509/b4c32ec02196324b0328480d4b25e28b to your computer and use it in GitHub Desktop.
amazon customer reviews apex spider
List<String> targetList = new List<String>{'B01LR7151C','B06XY77N5N','B072J83YSM','B019YHGHX8','B01K5BTJH8','B01GIIVF6K','B003F6WENW','B0027TEADK','B012PJVQ7Y','B01IG0E1F0','B0072V6MIO','B0727TW22T','B01G7UJIVI','B01AIW6KZS','B00MH78O0M','B0756T5CD4'};
for(String target: targetList){
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setEndpoint('https://www.amazon.com/product-reviews/'+target);
req.setMethod('GET');
// req.setBody('{}');
HttpResponse res = http.send(req);
String result = res.getBody().substringBetween('totalReviewCount">', ' out of 5 stars');
// System.debug(LoggingLevel.INFO, '*** : ' + result);
System.debug(LoggingLevel.INFO, '*** ' + target + ': ' + result.replaceAll('([0-9,]+).+class="arp-rating-out-of-text">([0-9.]+)', '$1 $2'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment