-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathamazonReviews.py
More file actions
28 lines (23 loc) · 864 Bytes
/
amazonReviews.py
File metadata and controls
28 lines (23 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def getTopReviews(soup):
topReviewsList=list(soup.find_all("div","a-expander-content reviewText review-text-content a-expander-partial-collapse-content"))
topReviewsList=[element.text.strip().replace(
"Your browser does not support HTML5 video.",""
).strip() for element in topReviewsList]
return topReviewsList
def printTopReviews(soup):
try:
reviews=getTopReviews(soup)
except:
print("\n\n------------------unable to fetch reviews------------------\n\n")
return
total=len(reviews)
if total == 1:
aux="is"
elif total == 0:
print("\t(No reviews so far!)\n\n")
return
else:
aux="are"
print("Here {} some Top {} reviews from customers!\n".format(aux,total))
for i, review in enumerate(reviews,1):
print(i,review,sep=". ",end="\n\n")