python-豆瓣电影《肖申克的救赎》评论数据爬取

最终词图效果:
在这里插入图片描述

第一步:豆瓣电影《肖申克的救赎》评论数据(https://movie.douban.com/subject/1292052/comments?sort=time&status=P)

第二步:词频统计可视化展示

第三步:绘制词云图

第四步:

================================================================

配置准备

================================================================

#安装jieba分词和词云

pip install jieba

pip install wordcloud

#安装paddle

pip install –upgrade PaddlePaddle

#安装模型

#hub install porn_detection_lstm==1.1.0

pip install –upgrade paddlehub

pip install numpy

#安装Beautifulsoup

pip install BeautifulSoup4

问题:

1.UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xe8 in position 1: invalid continuation byte

解决方法:

1.不使用urlLib换做requests

2.去掉请求头中的 ‘Accept-Encoding’: ‘gzip, deflate, br’

3.返回值reponse 转字符串指定编码utf-8

# ‘Accept-Encoding’: ‘gzip, deflate, br’,

2.关于cookie

解决方法:

1.去豆瓣请求头中复制cookie设置到请求头中

‘Cookie’: ‘bid=WD6_t6hVqgM’

3.请求返回418的问题

解决方案模拟设置请求头,设置user-agent

‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36’,

4.使用beautifulsoup获取不到评论

解决方法:

第一步:指定解析参数为’lxml’

soupComment = BeautifulSoup(html, ‘lxml’)

第二步:

findAll方法指定css文件的class名

print(‘网页内容:’, soupComment.prettify()) comments = soupComment.findAll(class_=’short’)

源码地址:

https://gitee.com/mikite/python_sp_shawshank

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值