首页 > 编程语言 >凑个小热闹:python采集《狂飙》评论

凑个小热闹:python采集《狂飙》评论

时间:2023-02-09 14:56:17浏览次数:40  
标签:comment get python text score vote 凑个 狂飙 css

2023年首部爆款剧集《狂飙》一度冲上热搜第一,害的我两倍速熬夜看完了。

 

 

“是非面前稍不留神,就会步入万丈深渊,唯有坚守信仰,才能守得初心”

 

 

面对这么多广大网友的讨论,我也来凑上一个热闹

用python爬取《狂飙》评论数据

代码展示

部分代码展示

import requests
import parsel
# 我还录制了详细讲解的视频,直接在这个裙 708525271 自取,包括完整代码

headers = {
    'Cookie': '数据我都删除了,建议用自己的',
    'Host': '',
    'User-Agent': '',
}
for page in range(0, 4000):
    print(page)
    url = f'https://movie.douban.com/subject/35465232/comments?start={page*20}&limit=20&status=P&sort=new_score'
    response = requests.get(url=url, headers=headers)
    select = parsel.Selector(response.text)
    comments = select.css('.comment-item .comment')
    for comment in comments:
        name = comment.css('.comment-info a::text').get()
        try:
            score_str = comment.css('.comment-info .rating::attr(class)').get()
            score = score_str.replace('0 rating', '').replace('allstar', '')
        except:
            score = 0
        comment_time = comment.css('.comment-info .comment-time::text').get().strip()
        vote_count = comment.css('.comment-vote .votes.vote-count::text').get()
        comment_content = comment.css('.comment-content span::text').get()
        print(name, score, comment_time, vote_count, comment_content)

 

 

效果展示

 

 

不登录的话,只能采集部分,全部评论需要登录后才能爬取。

浏览器数据容易泄密,我都删掉了,大家自己修改一下。

 

 

最后

感谢你观看我的文章~本次航班到这里就结束

标签:comment,get,python,text,score,vote,凑个,狂飙,css
From: https://www.cnblogs.com/hahaa/p/17105263.html

相关文章

  • python数据抓取,抓点星星网的内容
    代码:#coding=utf-8importos,sys,reimportrequestsfromwebob.excimportstrip_tagsfromxpinyinimportPinyindefstr2dict(str):dict={}groups1......
  • Python-celery介绍与快速上手
    1.celery介绍:  celery是一个基于Python开发的模块,可以帮助我们在开发过程中,对任务进行分发和处理。            详细介绍取自:Python之celery的简介与使......
  • Python之ruamel.yaml模块详解(一)
    (Python之ruamel.yaml模块详解(一))1ruamel.yaml简介ruamel.yaml是一个yaml解析器;ruamel.yaml是一个用于Python的yaml1.2加载器/转储程序包;它是PyYAML3.11的衍生产品;r......
  • python多维数组的每列的最值
    python代码实现importnumpyasnpdefmaxmin(array):#求每列的最值maxlist=[]minlist=[]foriinrange(len(array[0])):#行数col=[]......
  • python3 时间戳转换
    importtimedeftime_conversion(times):#转换成新的时间格式(2016-05-0520:28:54)dt=time.strftime("%Y-%m-%d%H:%M:%S",time.localtime(times))......
  • Python 分支结构
    阅读目录​​应用场景​​​​if语句的使用​​​​例子1:英制单位英寸与公制单位厘米互换​​​​例子2:百分制成绩转换为等级制成绩​​​​例子3:输入三条边长,如果能构成三......
  • Python爬虫爬取html中div下的多个class标签并存入数据库
    使用python爬虫爬取html页面div中的多个class标签,获取后将数据存成列表,然后存入数据库importmysql.connectorimportpymysqlimportrequestsfrombs4importBeautif......
  • python开发笔记--ImportError: cannot import name 'sysconfig' from 'distutils' (/u
    异常情况:ubuntu20.4安装python3.10和pip后,执行piplist提示如下:ImportError:cannotimportname'sysconfig'from'distutils'(/usr/lib/python3.8/distutils/__init__......
  • Vitualenvwrapper: 管理 python的 虚拟环境
            linux:install  Vitualenvwrapper[user]-3D05SQ3:~/python/managing-python-packages-virtual-environments/flask/venv$python3-mpipi......
  • 1、python_批量检测端口号
    #!/usr/bin/envpython#coding:utf-8#Author:zikangimportsocketlist_str='''172.31.7.1038080172.31.7.1046379172.31.7.1053306'''OK_list=[]Timeo......