@@ -171,7 +171,7 @@ def all_evaluate(opts=None):
171171 num = ev .xpath ('b/text()' )[0 ]
172172 opts ['logger' ].debug ('num: %s' , num )
173173 except IndexError :
174- opts ['logger' ].warning (
174+ opts ['logger' ].info (
175175 'Can\' t find num content in XPath, fallback to 0' )
176176 num = 0
177177 N [na ] = int (num )
@@ -245,18 +245,55 @@ def ordinary(N, opts=None):
245245 opts ['logger' ].debug ('Loop: %d / %d' , idx + 1 , loop_times1 )
246246 pid = pid .replace ('//item.jd.com/' , '' ).replace ('.html' , '' )
247247 opts ['logger' ].debug ('pid: %s' , pid )
248- opts ['logger' ].info (f"\t { i } .开始评价订单\t { oname } [{ oid } ]" )
248+ opts ['logger' ].info (f"\t { i } .开始评价订单\t { oname } [{ oid } ]并晒图 " )
249249 url2 = "https://club.jd.com/myJdcomments/saveProductComment.action"
250250 opts ['logger' ].debug ('URL: %s' , url2 )
251251 xing , Str = generation (oname , opts = opts )
252252 opts ['logger' ].info (f'\t \t 评价内容,星级{ xing } :' + Str )
253+
254+ #获取图片
255+ opts ['logger' ].info (f'\t \t 开始获取图片' )
256+ url1 = (f'https://club.jd.com/discussion/getProductPageImageCommentList'
257+ f'.action?productId={ pid } ' )
258+ opts ['logger' ].debug ('Fetching images using the default URL' )
259+ opts ['logger' ].debug ('URL: %s' , url1 )
260+ req1 = requests .get (url1 , headers = headers )
261+ opts ['logger' ].debug (
262+ 'Successfully accepted the response with status code %d' ,
263+ req1 .status_code )
264+ if not req .ok :
265+ opts ['logger' ].warning (
266+ 'Status code of the response is %d, not 200' , req1 .status_code )
267+ imgdata = req1 .json ()
268+ opts ['logger' ].debug ('Image data: %s' , imgdata )
269+ if imgdata ["imgComments" ]["imgCommentCount" ] == 0 :
270+ opts ['logger' ].debug ('Count of fetched image comments is 0' )
271+ opts ['logger' ].debug ('Fetching images using another URL' )
272+ url1 = ('https://club.jd.com/discussion/getProductPageImage'
273+ 'CommentList.action?productId=1190881' )
274+ opts ['logger' ].debug ('URL: %s' , url1 )
275+ req1 = requests .get (url1 , headers = headers )
276+ opts ['logger' ].debug (
277+ 'Successfully accepted the response with status code %d' ,
278+ req1 .status_code )
279+ if not req .ok :
280+ opts ['logger' ].warning (
281+ 'Status code of the response is %d, not 200' ,
282+ req1 .status_code )
283+ imgdata = req1 .json ()
284+ opts ['logger' ].debug ('Image data: %s' , imgdata )
285+ imgurl = imgdata ["imgComments" ]["imgList" ][0 ]["imageUrl" ]
286+ opts ['logger' ].debug ('Image URL: %s' , imgurl )
287+ opts ['logger' ].info (f'\t \t 图片url={ imgurl } ' )
288+
253289 data2 = {
254290 'orderId' : oid ,
255291 'productId' : pid , # 商品id
256292 'score' : str (xing ), # 商品几星
257293 'content' : bytes (Str , encoding = "gbk" ), # 评价内容
258294 'saveStatus' : '1' ,
259- 'anonymousFlag' : '1'
295+ 'anonymousFlag' : '1' , # 是否匿名
296+ 'imgs' : imgurl , # 图片url
260297 }
261298 opts ['logger' ].debug ('Data: %s' , data2 )
262299 if not opts .get ('dry_run' ):
@@ -265,6 +302,7 @@ def ordinary(N, opts=None):
265302 else :
266303 opts ['logger' ].debug (
267304 'Skipped sending comment request in dry run' )
305+ opts ['logger' ].info (f"\t { i } .评价订单\t { oname } [{ oid } ]并晒图成功" )
268306 opts ['logger' ].debug ('Sleep time (s): %.1f' , ORDINARY_SLEEP_SEC )
269307 time .sleep (ORDINARY_SLEEP_SEC )
270308 idx += 1
@@ -499,7 +537,11 @@ def Service_rating(N, opts=None):
499537 opts ['logger' ].debug ('Commenting on items' )
500538 for i , Order in enumerate (Order_data ):
501539 oname = Order .xpath ('td[1]/div[1]/div[2]/div/a/text()' )[0 ]
502- oid = Order .xpath ('td[4]/div/a[1]/@oid' )[0 ]
540+ try :
541+ oid = Order .xpath ('td[4]/div/a[1]/@oid' )[0 ]
542+ except IndexError :
543+ opts ['logger' ].warning ('Failed to fetch oid' )
544+ continue
503545 opts ['logger' ].info (f'\t 开始第{ i + 1 } ,{ oname } ' )
504546 opts ['logger' ].debug ('oid: %s' , oid )
505547 url1 = (f'https://club.jd.com/myJdcomments/insertRestSurvey.action'
@@ -564,7 +606,7 @@ def main(opts=None):
564606 opts['logger'].debug('N value after executing No(): %s', N)
565607 '''
566608 if N ['待追评' ] != 0 :
567- opts ['logger' ].info ("3.开始批量追评! " )
609+ opts ['logger' ].info ("3.开始批量追评,注意:追评不会自动上传图片 " )
568610 N = review (N , opts )
569611 opts ['logger' ].debug ('N value after executing review(): %s' , N )
570612 N = No (opts )
0 commit comments