Skip to content

Commit 8bd73d6

Browse files
committed
improve the acquisition of comments
1 parent 46e5824 commit 8bd73d6

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

auto_comment_plus.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,23 @@
3030
'537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/'
3131
'537.36'
3232
}
33-
34-
35-
# 评价生成
36-
def generation(pname, _class=0):
33+
# 评价生成
34+
def generation(pname, _class=0, _type=1):
3735
list = ['商品名']
3836
list.clear()
3937
list.append(pname)
4038
for item in list:
4139
spider = jdspider.JDSpider(item)
42-
result = spider.getData(4, 3) #这里可以自己改
40+
#增加对增值服务的评价鉴别
41+
if "赠品" in pname or "非实物" in pname or "增值服务" in pname :
42+
result = ["赠品挺好的。",
43+
"很贴心,能有这样免费赠送的赠品",
44+
"正好想着要不要多买一份增值服务,没想到还有这样的赠品。",
45+
"赠品正合我意。",
46+
"赠品很好,挺不错的。"
47+
]
48+
else:
49+
result = spider.getData(4, 3) #这里可以自己改
4350

4451
# class 0是评价 1是提取id
4552
try:
@@ -50,14 +57,19 @@ def generation(pname, _class=0):
5057
return name
5158
else:
5259
comments = ''
53-
if len(result) > 8 :
54-
for i in range(8):
55-
comments = comments + result.pop()
60+
if _type == 1:
61+
num = 8
62+
elif _type == 0:
63+
num = 5
64+
if len(result) < num :
65+
num = len(result)
5666
else:
57-
for i in range(len(result)):
58-
comments = comments + result.pop()
59-
return 5, (
60-
comments.replace("$", name))
67+
num = num
68+
for i in range(num):
69+
comments = comments + result.pop(random.randint(0, len(result) - 1))
70+
71+
72+
return 5, comments.replace("$", name)
6173

6274

6375
# 查询全部评价
@@ -140,7 +152,6 @@ def sunbw(N):
140152

141153
print(f'\t开始晒单{i},{oname}')
142154
# 获取图片
143-
pname = generation(pname=oname, _class=1)
144155
url1 = (f'https://club.jd.com/discussion/getProductPageImageCommentList'
145156
f'.action?productId={pid}')
146157
imgdata = requests.get(url1, headers=headers).json()
@@ -202,7 +213,7 @@ def review(N):
202213
pid, oid = _id.replace(
203214
'http://club.jd.com/afterComments/productPublish.action?sku=',
204215
"").split('&orderId=')
205-
context = generation(oname)
216+
_ , context = generation(oname,_type=0)
206217
print(f'\t\t追评内容:{context}')
207218
req_url1 = requests.post(url1, headers=headers, data={
208219
'orderId': oid,

0 commit comments

Comments
 (0)