Skip to content

Instantly share code, notes, and snippets.

@BernardOng
Created August 22, 2016 00:33
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 BernardOng/58efeb850dc43f1f0b9831dfa35d3ab5 to your computer and use it in GitHub Desktop.
Save BernardOng/58efeb850dc43f1f0b9831dfa35d3ab5 to your computer and use it in GitHub Desktop.
def processRecord(self, html):
# Single item processor
title = html.find('h2').text
price = html.find('span', {'class':'s-price'})
rating = html.find('span', {'class':'a-icon-alt'})
reviews = html.find('div', {'class':'a-span-last'})
# Process Reviews
if reviews:
for a in reviews.find_all(lambda a: (a.name=='a' and \
'customerReviews' in a['href']), href=True):
stringer = a.text
stringer = stringer.replace(',','')
reviews = int(stringer)
# Return Result
if title and price and rating and reviews:
return title, float(price.text.replace(',', '')[1:]), float(rating.text.replace(' out of 5 stars', '')), reviews
else: return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment