File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import requests
2+ import re
23from bs4 import BeautifulSoup
34from urllib .parse import urlparse
45
@@ -40,13 +41,16 @@ def amazon(text):
4041 price = item .find ('span' , {'class' : 'a-color-price' }).text
4142
4243 try :
44+ pattern = re .compile (r'product-reviews' )
4345 rating = item .find ('i' , {'class' : 'a-icon-star' }).find ('span' , {'class' : 'a-icon-alt' }).text
46+ num_ratings = item .find ('a' , {'href' : pattern }).text
47+ rating_str = "{} ({} ratings)" .format (rating , num_ratings )
4448 except AttributeError :
45- rating = "No Ratings"
49+ rating_str = "No Ratings"
4650
4751 # clean up garbage url
4852 o = urlparse (item .find ('a' , {'class' : 's-access-detail-page' })['href' ])
4953 url = o .scheme + "://" + o .netloc + o .path + "?linkCode=as2&tag=cloudbot-20"
5054 url = web .try_shorten (url )
5155
52- return "\x02 {}\x02 ({}) - {} - {}" .format (title , price , rating , url )
56+ return "\x02 {}\x02 ({}) - {} - {}" .format (title , price , rating_str , url )
You can’t perform that action at this time.
0 commit comments