This commit is contained in:
dylan 2022-10-02 15:23:41 +08:00
parent ee95f69065
commit 740bd36cb7
4 changed files with 21 additions and 35 deletions

View File

@ -1,2 +1,8 @@
# auto_comment
自动评价
自动评价,带图
![image](./img/1.jpg)
拉库命令 ql repo https://github.com/6dylan6/auto_comment.git "jd_" "" "jdspider"
浏览器登录抓取ck添加变量PC_COOKIE每次运行最多评价10个订单
在原库https://github.com/Dimlitter/jd_AutoComment进行修改优化适配青龙自动安装依赖

BIN
img/1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@ -7,7 +7,6 @@
new Env('自动评价');
8 8 2 10 * https://raw.githubusercontent.com/6dylan6/auto_comment/main/jd_comment.py
'''
import argparse
import copy
import logging
@ -26,7 +25,7 @@ except:
os.system('pip3 install lxml &> /dev/null')
os.system('pip3 install jieba &> /dev/null')
os.system('pip3 install zhon &> /dev/null')
import jieba # just for linting
import jieba
import jieba.analyse
#import yaml
from lxml import etree
@ -239,7 +238,7 @@ def sunbw(N, opts=None):
opts['logger'].info(f"当前共有{N['待评价订单']}个需要评价晒单。")
opts['logger'].debug('Commenting on items')
for i, Order in enumerate(Order_data):
if i > 1:
if i +1 > 10:
opts['logger'].info(f'\t已评价10个订单跳出')
break
oname = Order.xpath(
@ -253,7 +252,7 @@ def sunbw(N, opts=None):
opts['logger'].debug('pid: %s', pid)
opts['logger'].debug('oid: %s', oid)
xing, Str = generation(oname, opts=opts)
opts['logger'].info(f'\t\评价内容:{xing}' + Str)
opts['logger'].info(f'\t评价信息:{xing}' + Str)
# 获取图片
url1 = (f'https://club.jd.com/discussion/getProductPageImageCommentList'
f'.action?productId={pid}')
@ -287,7 +286,7 @@ def sunbw(N, opts=None):
imgurl = imgdata["imgComments"]["imgList"][0]["imageUrl"]
opts['logger'].debug('Image URL: %s', imgurl)
opts['logger'].info(f'\t图片url={imgurl}')
opts['logger'].info(f'\t图片{imgurl}')
# 提交晒单
opts['logger'].debug('Preparing for commenting')
url2 = "https://club.jd.com/myJdcomments/saveProductComment.action"
@ -366,7 +365,7 @@ def review(N, opts=None):
opts['logger'].info(f"当前共有{N['待追评']}个需要追评。")
opts['logger'].debug('Commenting on items')
for i, Order in enumerate(Order_data):
if i + 1 > 1:
if i + 1 > 10:
opts['logger'].info(f'\t已评价10个订单跳出')
break
oname = Order.xpath('td[1]/div/div[2]/div/a/text()')[0]
@ -450,7 +449,7 @@ def Service_rating(N, opts=None):
opts['logger'].info(f"当前共有{N['服务评价']}个需要服务评价。")
opts['logger'].debug('Commenting on items')
for i, Order in enumerate(Order_data):
if i + 1 > 1:
if i + 1 > 10:
opts['logger'].info(f'\t已评价10个订单跳出')
break
oname = Order.xpath('td[1]/div[1]/div[2]/div/a/text()')[0]
@ -478,7 +477,7 @@ def Service_rating(N, opts=None):
pj1 = requests.post(url1, headers=headers, data=data1)
else:
opts['logger'].debug('Skipped sending comment request in dry run')
opts['logger'].info("\t\t " + pj1.text)
opts['logger'].info("\t " + pj1.text)
opts['logger'].debug('Sleep time (s): %.1f', SERVICE_RATING_SLEEP_SEC)
time.sleep(SERVICE_RATING_SLEEP_SEC)
N['服务评价'] -= 1
@ -522,10 +521,6 @@ def main(opts=None):
N = No(opts)
opts['logger'].debug('N value after executing No(): %s', N)
opts['logger'].info("本次运行完成!")
#for i in N:
# if N[i] != 0:
# opts['logger'].warning("出现了二次错误,跳过了部分,重新尝试")
# main(opts)
if __name__ == '__main__':
@ -624,9 +619,10 @@ if __name__ == '__main__':
if "PC_COOKIE" in os.environ:
if len(os.environ["PC_COOKIE"]) > 1:
ck = os.environ["PC_COOKIE"]
logger.info ("已获取并使用Env环境 Cookie")
#ck = cfg['user']['cookie']
logger.info ("已获取环境变量 CK")
else:
logger.info("请添加电脑端CK变量PC_COOKIE")
sys.exit(1)
headers = {
'cookie': ck.encode("utf-8"),
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36',

View File

@ -1,5 +1,5 @@
# @Time : 2022/2/10
# @Author :@Zhang Jiale and @Dimlitter @Dylan
# @Time : 2022/10/2
# @Author :@Zhang Jiale @Dimlitter @6dylan6
# @File : jdspider.py
import json
@ -69,24 +69,8 @@ class JDSpider:
def getHeaders(self, productid): # 和初始的self.header不同这是搜集某个商品的header加入了商品id我也不知道去掉了会怎样。
header = {
"Referer": "https://item.jd.com/%s.html" % (productid),
"Host": "sclub.jd.com",
"Connection": "keep-alive",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"sec-ch-ua": '"Chromium";v="21", " Not;A Brand";v="99"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "Windows",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Sec-Fetch-Site": "none",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9",
"upgrade-insecure-requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36",
"Cookie": self.ck
"Cookie": self.ck.encode("utf-8")
}
return header