-
-
Save BernardOng/58efeb850dc43f1f0b9831dfa35d3ab5 to your computer and use it in GitHub Desktop.
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
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