1. 中文字体下载不成功
需要从别处下载,然后上传:
https://www.uslogger.com/details/3
http://www.font5.com.cn/font_download.php?id=151&part=1237887120
2. 柱状图不显示中文
原因:
1) 没有安装中文字体,详细内容见上面1
2) 安装了中文字体,但是没有复制到matplotlib下面
#1 将字体文件复制到matplotlib字体路径
!cp simhei.ttf /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/
#2 一般只需要将字体文件复制到系统字体目录下即可,但是在aistudio上该路径没有写权限,所以此方法不能用
# !cp simhei.ttf /usr/share/fonts/
#3 创建系统字体文件路径
!mkdir .fonts
# 复制文件到该路径
!cp simhei.ttf .fonts/
#4
!rm -rf .cache/matplotlib
3) 设置matplotlib.rcParams
plt.rcParams['font.sans-serif'] = ['SimHei']
4) for mac:安装好以后需要使用rm -r ~/.matplotlib 删除~/.matplotlib文件
5) 查看系统可用的ttf格式中文字体
!fc-list :lang=zh | grep ".ttf"
/home/aistudio/.fonts/simhei.ttf: SimHei,黑体:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
可知如果设置了:
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf/simhei.ttf
或
.fonts/simhei.ttf
最终使用.fonts/simhei.ttf
6)设置好后,如果不起作用,需要重新进入AIStudio
3. 爬去爱奇艺comments,找不到comments路径
F12,network,找到get_comments.atcion
jsonp_xxx后面是随机生成的,通过callback参数传给后端然后你会看到后端会返回jsonp_xxx()这相当于调用了一个方法,这个方法会处理返回的data,而zh’ge方法前端这边已经生成了,也叫做回调,具体的可以百度jsonp解决跨域问题了解下。所以在爬数据时就不需要带上callback参数了,这个参数是跟后端说等下返回后回调的方法名。
最后需要的url:
url = "https://sns-comment.iqiyi.com/v3/comment/get_comments.action?" \
"agent_type=118" \
"&agent_version=9.11.5" \
"&authcookie=null" \
"&business_type=17" \