-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.py
90 lines (76 loc) · 3.45 KB
/
review.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
class Review:
def __init__(self, rev_block):
self.rev_block = rev_block
self.rev_id = rev_block['data-entry-id']
self.desc = self.getDesc()
self.stars = self.getStars()
self.author = self.getAuthor()
self.rev_positive_votes = self.getPositiveVotes()
self.rev_negative_votes = self.getNegativeVotes()
self.recommended = self.getRecommended()
self.rev_date = self.getRevDate()
self.buy_date = self.getBuyDate()
self.pros = self.getPros()
self.pros_count = self.getProsCount()
self.cons = self.getCons()
self.cons_count = self.getConsCount()
self.bought = self.getBought()
self.rev_block=1
def getProsCount(self):
return len(self.pros)
def getConsCount(self):
return len(self.cons)
def getPositiveVotes(self):
vote_button = self.rev_block.find("button", attrs={"data-review-id": self.rev_id,
"class": 'vote-yes js_product-review-vote js_vote-yes'})
return vote_button['data-total-vote']
def getNegativeVotes(self):
vote_button = self.rev_block.find("button", attrs={"data-review-id": self.rev_id,
"class": 'vote-no js_product-review-vote js_vote-no'})
return vote_button['data-total-vote']
def getBought(self):
return True if self.rev_block.find(class_='review-pz') else False
def getDesc(self):
return self.rev_block.find(class_='user-post__text').text
def getStars(self):
return self.rev_block.find(class_='user-post__score-count').text
def getAuthor(self):
return self.rev_block.find(class_='user-post__author-name').text
def getRecommended(self):
recomendation = ''
if self.rev_block.find(class_='recommended'):
recomendation = self.rev_block.find(class_='recommended').text
elif self.rev_block.find(class_='not-recommended'):
recomendation = self.rev_block.find(class_='not-recommended').text
return recomendation
def getRevDate(self):
post_dates = self.rev_block.find(class_='user-post__published')
user_dates = post_dates.find_all('time')
return user_dates[0]['datetime']
def getBuyDate(self):
post_dates = self.rev_block.find(class_='user-post__published')
user_dates = post_dates.find_all('time')
try:
return user_dates[1]['datetime']
except:
return ''
def getPros(self):
pros_list = []
if self.rev_block.find(class_='review-feature'):
col = self.rev_block.find_all(class_='review-feature__col')
for x in col:
if x.find(class_='review-feature__title review-feature__title--positives'):
pros = x.find_all(class_='review-feature__item')
for pro in pros:
pros_list.append(pro.text)
return pros_list
def getCons(self):
cons_list = []
if self.rev_block.find(class_='review-feature'):
col = self.rev_block.find_all(class_='review-feature__col')
for x in col:
if x.find(class_='review-feature__title review-feature__title--negatives'):
cons = x.find_all(class_='review-feature__item')
for con in cons:
cons_list.append(con.text)
return cons_list