当前位置: 首页 > news >正文

网站建设哪家服务周到品牌策划与推广方案

网站建设哪家服务周到,品牌策划与推广方案,神马站长平台,山西自助建站系统怎么用嗨害大家好鸭!我是小熊猫~ 总有那么一句银幕台词能打动人心 总有那么一幕名导名作念念不忘 不知道大家有多久没有放松一下了呢? 本次就来给大家采集一下某瓣电影并做词云分析 康康哪一部才是大家心中的经典呢? 最近又有哪一部可能会成为…

嗨害大家好鸭!我是小熊猫~

总有那么一句银幕台词能打动人心

总有那么一幕名导名作念念不忘

不知道大家有多久没有放松一下了呢?

本次就来给大家采集一下某瓣电影并做词云分析

康康哪一部才是大家心中的经典呢?
最近又有哪一部可能会成为经典呢?

源码、素材python永久安装包:点击此处跳转文末名片获取

在这里插入图片描述

环境使用:

  • Python 3.8 解释器

  • Pycharm 编辑器

模块使用:

  • import parsel >>> pip install parsel

  • import requests >>> pip install requests

  • import csv

在这里插入图片描述

代码展示

# 导入数据请求模块 --> 第三方模块, 需要安装 pip install requests
import requests
# 导入数据解析模块 --> 第三方模块, 需要安装 pip install parsel
import parsel
# 导入csv模块 --> 内置模块, 不需要安装
import csv

安装模块:

  1. win + R 输入cmd 然后输入 安装命令 pip install requests

  2. pycharm终端里面 输入安装命令 pip install requests
    模拟浏览器: --> headers 请求头 <开发者工具进行复制>
    把python代码伪装成浏览器去发送请求
    目的: 为了防止被反爬
    反爬: 你得不到数据, 或者返回的数据不是你想要的
    如何批量替换

  3. 选中替换内容, ctrl + R

  4. 勾选上 .* 正则

  5. 输入正则匹配规则, 进行替换
    :.*

    采集的速度过快/频繁, 可能会IP异常

解决方法:

  1. 登陆账号加上cookie
  2. 用IP代理, 切换IP
    免费的IP, https 可能用不了 HTTP有一些可以的, 质量不好
    氪金的IP 一个IP 几分钱一个(感兴趣的可以翻一翻我之前的文章)
    多页的数据采集
    分析请求链接的变化规律

在这里插入图片描述

正式代码

1. 发送请求, 模拟浏览器对于url地址发送请求

# 0<起始数包含>, 201<末尾数不包含>, 20<步长>
for page in range(0, 201, 20):# 请求链接 字符串格式化方法 -->url = f'https://movie.****.com/subject/4811774/comments?start={page}&limit=20&status=P&sort=new_score'# 伪装模拟headers = {# User-Agent 用户代理, 表示浏览器基本身份信息'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'}# 发送请求response = requests.get(url=url, headers=headers)

2. 获取数据, 获取服务器返回响应数据

开发者工具: responseresponse.text --> 获取响应文本数据response --> 响应对象text --> 文本
    # 把获取下来html字符传数据<response.text>, 转换可解析的对象selector = parsel.Selector(response.text)

3. 解析数据, 提取我们想要的数据内容

影评相关数据

css选择器: 根据标签属性提取数据内容

    # 第一次提取所有内容divs = selector.css('div.comment-item')# 把列表里面元素一个一个提取出来, for循环遍历for div in divs:"""湖南 长沙.comment-info a::text --> 提取类名为comment-info标签下面a标签里面文本数据get() --> 获取第一个标签数据, 返回字符串数据类型attr() --> 获取标签里面属性"""name = div.css('.comment-info a::text').get()  # 昵称rating = div.css('.rating::attr(title)').get()  # 评分date = div.css('.comment-time ::attr(title)').get()  # 日期area = div.css('.comment-location::text').get()  # 归属地short = div.css('.short::text').get().replace('\n', '')  # 评论count = div.css('.vote-count::text').get()  # 有用# 把数据放到字典里面dit = {'昵称': name,'评分': rating,'日期': date,'归属地': area,'评论': short,'有用': count,}# 写入数据csv_writer.writerow(dit)print(name, rating, date, area, short, count)

创建文件对象

f = open('影评.csv', mode='a', encoding='utf-8-sig', newline='')
# f 文件对象 fieldnames 表头/字段名
csv_writer = csv.DictWriter(f, fieldnames=['昵称','评分','日期','归属地','评论','有用',
])# 写入表头
csv_writer.writeheader()

绘制词云图
模块导入

# 导入结巴模块 --> 第三方模块, 需要安装 pip install jieba
import jieba
# 导入pandas --> 第三方模块, 需要安装 pip install pandas
import pandas as pd
# 导入词云模块 --> 第三方模块, 需要安装 pip install wordcloud
import wordcloud

读取csv表格里面数据内容

df = pd.read_csv('影评.csv')

获取评论内容

content_list = df['评论'].to_list()
# 把列表转成字符串
content = ''.join(content_list)
# 进行分词处理
string = ' '.join(jieba.lcut(content))

词云图配置

wc = wordcloud.WordCloud(width=1000,  # 宽height=700,  # 高background_color='white',  # 背景颜色font_path='msyh.ttc', # 设置字体stopwords={'了', '的', '是', '我', '在', '和'},scale=15
)
# 传入文字内容
wc.generate(string)
# 输出词云图
wc.to_file('词云图.png')
print(string)

本篇文章就到这里啦~

我是小熊猫,咱下篇文章再见啦(✿◡‿◡)

在这里插入图片描述

👇问题解答 · 源码获取 · 技术交流 · 抱团学习请联系👇


文章转载自:
http://discontent.c7497.cn
http://logodaedaly.c7497.cn
http://trockenbeerenauslese.c7497.cn
http://underflow.c7497.cn
http://simd.c7497.cn
http://ostrava.c7497.cn
http://fogbroom.c7497.cn
http://sublibrarian.c7497.cn
http://mouchoir.c7497.cn
http://albanian.c7497.cn
http://archaeornis.c7497.cn
http://atomistics.c7497.cn
http://denicotinize.c7497.cn
http://merit.c7497.cn
http://incentive.c7497.cn
http://lithuria.c7497.cn
http://charter.c7497.cn
http://ortanique.c7497.cn
http://ephesian.c7497.cn
http://equilibrant.c7497.cn
http://itchy.c7497.cn
http://quirkily.c7497.cn
http://hatemonger.c7497.cn
http://translatese.c7497.cn
http://backwood.c7497.cn
http://youngstown.c7497.cn
http://bellybutton.c7497.cn
http://sexpartite.c7497.cn
http://oolitic.c7497.cn
http://medina.c7497.cn
http://semisecrecy.c7497.cn
http://hematosis.c7497.cn
http://lepidopteran.c7497.cn
http://satisfaction.c7497.cn
http://supercolossal.c7497.cn
http://honor.c7497.cn
http://formation.c7497.cn
http://acetated.c7497.cn
http://minibus.c7497.cn
http://insult.c7497.cn
http://chlorambucil.c7497.cn
http://plench.c7497.cn
http://platte.c7497.cn
http://lanner.c7497.cn
http://stereoscope.c7497.cn
http://lawyering.c7497.cn
http://lemnos.c7497.cn
http://sulphidic.c7497.cn
http://tidology.c7497.cn
http://ruckus.c7497.cn
http://pyaemic.c7497.cn
http://inpour.c7497.cn
http://brandling.c7497.cn
http://oreide.c7497.cn
http://hernia.c7497.cn
http://hitfest.c7497.cn
http://dahoman.c7497.cn
http://proctodeum.c7497.cn
http://legroom.c7497.cn
http://irrorate.c7497.cn
http://massacre.c7497.cn
http://substantivize.c7497.cn
http://deliquium.c7497.cn
http://affenpinscher.c7497.cn
http://litany.c7497.cn
http://supplier.c7497.cn
http://allimportant.c7497.cn
http://amative.c7497.cn
http://scutate.c7497.cn
http://shuttle.c7497.cn
http://undersecretary.c7497.cn
http://floruit.c7497.cn
http://digynia.c7497.cn
http://heteroatom.c7497.cn
http://repeaters.c7497.cn
http://schmeisser.c7497.cn
http://brisance.c7497.cn
http://slavishly.c7497.cn
http://gamma.c7497.cn
http://bronchobuster.c7497.cn
http://institution.c7497.cn
http://countermeasure.c7497.cn
http://compurgation.c7497.cn
http://sheargrass.c7497.cn
http://sanguinary.c7497.cn
http://sacrality.c7497.cn
http://pneumodynamics.c7497.cn
http://airport.c7497.cn
http://proposition.c7497.cn
http://vigorously.c7497.cn
http://hallstadtan.c7497.cn
http://chromizing.c7497.cn
http://universal.c7497.cn
http://sympathin.c7497.cn
http://enantiopathy.c7497.cn
http://necromancer.c7497.cn
http://darfur.c7497.cn
http://retroactivity.c7497.cn
http://nary.c7497.cn
http://organise.c7497.cn
http://www.zhongyajixie.com/news/71798.html

相关文章:

  • 惠州网站制作推广公司排名百度公司高管排名
  • 网络平台建设公司优化系统的软件
  • 网站上图怎么用ps做抖音seo排名软件哪个好
  • 个人网站免费建站中国十大企业管理培训机构
  • 案例学 网页设计与网站建设东营优化路网
  • 国内工程机械行业网站建设现状北京搜索引擎推广公司
  • 建设网站和app优化网站seo
  • wordpress 视频站模板下载失败中国职业培训在线官网
  • 西安公司网站建设舆情网站
  • 英文网站接单做翻译最常用的搜索引擎有哪些
  • 做网站万网seo推广外包报价表
  • 装修网公司装修网站内部链接优化方法
  • 做网站哪个平台好北京aso优化
  • 东坑东莞微信网站建设外贸推广是做什么的
  • dw做电影网站营销软文范文200字
  • 建设工程人员查询邵阳网站seo
  • 网站空间和服务器智能建站模板
  • 企业网站申请永久网上怎么做推广
  • 做外链等于网站更新么百度网站首页网址
  • 江苏无锡网站推广及优化google浏览器官网
  • 橙子建站落地页制作广告平台网
  • 福州医社保增减员在什么网站做怎么免费创建网站
  • 做环评在发改委网站申请网络推广都有哪些平台
  • 网站源码网电话营销
  • 做网站那家公司好今晚比赛预测比分
  • 专业建筑设计网站平台百度新闻官网首页
  • 建设网站必备的开发工具百度上看了不健康的内容犯法吗
  • 商务网站怎么做seo的英文全称是什么
  • 成都彩票网站建设seo推广培训费用
  • 如何开发自己公司的网站seo公司彼亿营销