defgetJDProdComment(prod_skuId): big_pag_path = '//img30.360buyimg.com/shaidan/s616x405_jfs/'# 评价大图地址 tiny_pag_path = '//img30.360buyimg.com/n0/s128x96_jfs/'# 评价缩略图地址 for i in range(page_range): comments_url = 'https://api.m.jd.com/?appid=item-v3&functionId=pc_club_productPageComments&client=pc&clientVersion=1.0.0&t=1705853247039&loginType=3&uuid=181111935.16953916127351737253418.1695391613.1705847111.1705852812.35&productId='+str(prod_skuId)+'&score=0&sortType=5&page='+str(i)+'&pageSize=10&isShadowSku=0&fold=1&bbtf=&shield=' data = requests.get(comments_url, headers=headers) if data: content_data=data.content.decode('utf-8') json_data=json.loads(content_data) print(json_data) if i == 0: productCommentSummary=json_data.get('productCommentSummary') print(prod_skuId, str(productCommentSummary)) hotCommentTagStatistics=json_data.get('hotCommentTagStatistics') print(prod_skuId,str(hotCommentTagStatistics)) comments=json_data.get('comments') if comments and len(comments)>0: for comment in comments: prod_comment_guid=comment.get('guid') prod_comment_content=str(comment.get('content')) prod_comment=str(comment) images=comment.get('images') savepath=os.path.join(jd_prod_pic_save_path,str(prod_skuId),'comments',prod_comment_guid) if images and len(images)>0: for image in images: str_image_url=image.get('imgUrl').replace(tiny_pag_path, big_pag_path) image_url='https:'+str_image_url filename=os.path.basename(image_url) downloadfile(image_url, savepath, filename) #下载图片 time.sleep(sleeptime) print(prod_comment_guid,prod_skuId,prod_comment_content,prod_comment) time.sleep(sleeptime)
评论