最佳评论:非常好!剧情有倒叙,看不懂的可以看!任嘉伦的演技很好,兰悦和林静很容易分开。萌萌的演技一点都不尴尬,还挺好看的!常慧文也蛮可爱的~剧情倒叙很多,作为原创剧本我个人还是很满意的!每个人都有自己的小秘密,需要观众去揣摩~没有绝对的反派,明尊我也很满意。倒也不是很讨厌,可能是因为演技太好了,让林远圈粉了!先给实景拍摄点个赞吧!真的很美,好久没有看到几乎全真人的武侠剧了!!!包括刺马蜂窝的场景。这是一次真实的射击。看到这样的良心剧真的很开心!!剧情不拖沓,不灌水,不戏水,人物性格鲜明。每个人都有自私,但都能看到可怜的一面。你看到的感情线很多都是相互利用的,太强大了!男女主有仇,看似家常便饭,但实际上,这种仇恨根本不影响他们的感情。林若寒也非常支持林静追求真爱,不希望前世的恩怨留给下一代。是个很好的妈妈最差评价:麻辣鸡片,一点都不好吃好评:68.4%恒大代理申请http://www.kaifx.cn/broker/ha...代码部分importrequestsfrombs4importBeautifulSoupimporttracebackimportcsvimportjiebaimportcsvfromwordcloudimportWordCloudimportnumpyasnpfromPILimportImageimportknownlpimportmatplotlib.pyplotaspltfrommatplotlib.font_managerimportFontProperties定义了每页请求影评的方法header={'Accept':'text/html,application/xhtml/xml,xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',"Connection":"keep-alive","User-Agent":"Mozilla/5.0(X11;Linuxx86_64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/83。0.4103.116Safari/537.36","Cookie":'bid=HPwx786ji5w;douban-fav-remind=1;viewed="22601258";gr_user_id=954bdfba-9778-4359-b238-cd539123a160;_vwo_uuid_v2=D7DD1B1011AD0B9B5B3332525CEEF25CF|9b95f719e9255f99462f09e1248197a2;__utmz=223695111.1592467854.1.1.utmcsr=baidu|utmccn=(organic)|utmcmd=organic;ll="118254";__utmc=30149280;__utmc=223695111;ap_v=0,6.0;__utma=30149280.349582947.1592100671.1592986456.1592989460.7;__utmz=30149280.1592989460.7.5.utmcsr=百度|utmccn=(有机)|utmcmd=有机;_pk_ref.100001.4cf6=%5B%22%22%2C%22%22%2C1592989707%2C%22https%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D_7ZcG2FOcVjzEmAtnon0r-2-zpQeowzBEOKVYuJSrfmg_SLF6-lCeZXNH6BtW6ig%26wd%3D%26eqid%3Da740e3ec00010995000000065eeb1ef0%22%5D;_pk_ses.100001.4cf6=*;__utma=223695111.1175335955.1592467854.1592986456.1592989707.4;__utmb=223695111.0.10.1592989707;__utmb=30149280.5.10.1592989460;_pk_id.100001.4cf6=263156288f9d7135.1592467854.4.1592992247.1592986526.'}评分=[0,0,0,0,0]AllRating=0star_List=['非常差','差','还好','推荐','强烈推荐']defgetCommentByPage(url,commentList):4.添加Request头requestresponse=requests.get(url,headers=header)ifresponse.status_code==200:bs=BeautifulSoup(response.content,"html5lib")commentItemList=bs.select(".comment-item")try:forcommentItemincommentItemList:print(commentItem)comment=commentItem.select_one(".comment")commentInfo=comment.select_one(".comment-info")Getcommenterauther=commentInfo.select_one("a").textprint(作者)获得评级star=commentInfo.select_one(".rating")if(star!=None):star1=star.get('title')print(star1)foriinrange(0,5):if(star1==star_List[i]):rating[i]+=1commentContent=comment.select_one(".short").text.replace("\n","")如果不是star==None:print(auther,"---",star['title'],"----",commentContent)commentList.append([auther,star['title'],commentContent])returncommentListexceptException:#打印异常信息print(traceback.print_exec())passdefreadData():commentList=[]withopen(f"{name}.csv",'r',encoding="utf-8")asfile:csvReader=csv.reader(file)print(csvReader)遍历迭代4.使用列表生成return[item[2]foritemincsvReader]passdefgenerateWordCloud():commentList=readData()finalComment=""k=0m=0#loadstopdictionarystop_words=[w.strip()forwinopen('cn_stopwords.txt',encoding="utf-8").readlines()]max=snownlp.SnowNLP(commentList[0]).sentimentsmaxtag=commentList[0]min=snownlp.SnowNLP(commentList[0]).sentimentsmintag=commentList[0]forcommentincommentList:#如果不停止将结果集添加到这个tableifcommentnotinstop_words:finalComment+=comments=snownlp.SnowNLP(comment)#对无评论进行情感分析评分累加k=k+s.sentiments#累加总评论数m=m+1ifmaxs.sentiments:min=s.sentimentsmintag=commentf=open(name+".txt","w",encoding="utf-8")str1=maxtag+"\n"str1=str1+"最差评价:"+mintag+"\n"str1=str1+"好评:"+str(round(k/m,3)*100)+"%"+"\n"f.write(str1)finalComment="".join(jieba.cut(finalComment))自定义词云轮廓图=np.array(Image.open("1.png"))4.生成词云font_path字体路径background_color背景色遮罩:自定义图片生成轮廓慈云wordCloud=WordCloud(font_path="YaHeiMonacoHybrid.ttf",background_color="white",mask=image).generate(finalComment)保存并生成本地词云wordCloud.to_file(f"{name}.png")defgeneratePie():try:foriinrange(0,5):AllRating=AllRating+rating[i]foriinrange(0,5):rating[i]=rating[i]/AllRatingexcept异常:passfont=FontProperties(fname='YaHeiMonacoHybrid.ttf',size=16)plt.pie(x=评级,标签=['1','2','3','4','5'],颜色=['红色','粉红色','蓝色','紫色','橙色'],startangle=90,shadow=True,explode=tuple(indic),#tuple方法用于将list转成tupleautopct='%1.1f%%'#是数字1,不是l)plt.title(u'表扬分析',FontProperties=font)plt.savefig(name+"_piechart.jpg")plt.show()if__name__=='__main__':commentList=[]url=input('请输入id要分析的电影:(例子:https://movie.douban.com/subj...')print("ID--------star------------review\n")name=""foriinrange(10):baseUrl=f"https://movie.douban.com/subject/30425206/comments?start={i*20}"baseUrl=f"https://movie.douban.com/subject/{url}/comments?start={i*20}"response=requests.get(baseUrl,headers=header)ifresponse.status_code==200:bs=BeautifulSoup(response.content,"html5lib")name=bs.title.textname=name.strip()commentList=getCommentByPage(baseUrl,commentList)withopen(f"{name}.csv",'w',newline="",encoding="utf-8")作为文件:csvWriter=csv.writer(file)print(commentList)csvWriter.writerows(commentList)f=open(name+".txt","w",encoding="utf-8")str1=name+"\n"+"最佳评价:"f.write(str1)generateWordCloud()generatePie()print("分析完成")
