Giter Club home page Giter Club logo

weibospider_forcomments_reposts_attitudes's Introduction

功能

本程序可以根据微博的mid爬取对应微博的点赞、转发与评论的几乎全部信息,并将结果写入csv文件中。

代码结构

文件名 函数名 功能
parseAttitude init 定义cookie、weibo_id、headers等参数
SpiderAttitude 构造点赞的url并解析点赞页的数据,包括点赞页翻页等功能
CsvPipeLineAttitude 创建csv文件并将解析好的result_lines列表写入文件
parseRepost init 定义cookie、weibo_id、headers等参数
SpiderTransmit 构造转发页url并爬取所有转发人信息,包括转发页翻页等功能
CsvPipeLineTransmit 创建csv文件并将解析好的result_lines列表写入文件
parseComments init 定义cookie、weibo_id、headers等参数
main 构造一级评论的url,提取翻页所用的相关参数,调用parse_response_data函数解析一级评论,包括一级评论翻页等内容
parse_response_data 解析一级评论的所有信息,并判断是否有二级评论,若有二级评论,则构造二级评论url,提取相关翻页参数,调用parse_secondary_comments函数解析二级评论,包括二级评论翻页等内容
parse_secondary_comments 解析二级评论的所有信息
CsvPipeLineComment 创建csv文件并将解析好的result_lines列表写入文件
start 输入weibo_id和cookie,运行整个程序

输入和输出

输入

  • weibo_id = '详细博文的mid'
  • cookie = 'your cookie 值'

输出

会分别输出三个文件:
attitudes.csv:

  • mid:初始微博的mid,为一串数字形式
  • attitude_id:初始微博的每一条点赞的id
  • attitude_user_id:点赞用户的id
  • attitude_user_screen_name:点赞用户的昵称

reposts.csv:

  • mid:初始微博的mid,为一串数字形式
  • transmit_mid:初始微博的每一条转发的id
  • transmit_user_id:转发用户的id
  • transmit_user_screen_name:转发用户的昵称
  • 该条转发显示的文本内容(eg.“转发微博”字样)

comments.csv:

  • mid:初始微博的mid,为一串数字形式
  • comment_mid:初始微博的每一条一级评论的id
  • comment_user_id:一级评论用户的id
  • comment_user_screen_name:一级评论用户的昵称
  • comment_content:一级评论的文本内容
  • comment_pic_urls:一级评论中包含的图片url
  • has_comments:bool值,是否有二级评论
  • secondary_comments_num:二级评论的数量
  • secondary_comment_mid:二级评论的id
  • secondary_comment_user_id:二级评论用户的id
  • secondary_user_screen_names:二级评论用户的名称
  • secondary_comment_content:二级评论的文本内容
  • secondary_comment_pic_urls:二级评论中包含的图片url

运行程序

输入weibo_id与cookie后直接运行start.py即可

tips:

如何获取cookie

  1. 用Chrome打开https://weibo.com/
  2. 点击“立即登录”,完成私信验证或手机验证码验证,进入新版微博
  3. 按F12打开开发者工具,在开发者工具的Network->Name->weibo.cn->Headers->Request Headers,找到“cookie:"后的值,这就是我们需要的cookie值,复制即可,如图所示。
    如何获取初始微博的mid,即weibo-id
    方式一:
    通过其他微博爬虫,如关键字爬取微博内容等获取相应微博的mid
    方式二:(手动获取)
  4. 点击某条微博右上角向下箭头符号,复制微博链接
  5. 打开新链接,注意链接中最后一串字符串,F12打开开发者工具,在开发者工具的Network->Name中找到'show?id=刚才链接中的字符串'
  6. 点击后找到preview->“id:”,其中id后的值就是我们需要的微博mid,复制即可,如图所示。

weibospider_forcomments_reposts_attitudes's People

Contributors

gaoakajie avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.