Coder Social home page Coder Social logo

weibo_spider-scrapy's Introduction

容我在自己的项目前面写个求助

请问有没有人在 2022年11月14日之后使用过这个或其他备份微博的程序 对@不死人后院画符bot_ (数字id:7567516224) 进行过备份,这个账号里有一些评论内容对我来说很重要。

如果有人能给我这个账号的数据的话真的非常感谢,我可以为你写点代码,爬个网站(不保证能成总之我尽力)或者给现在这个程序加功能什么的

好了下面是这个程序的说明文档

使用


配置文件

配置文件在configs下,n1_userWb_config.json是爬取用户微博的配置文件,改这个就行。 l开头的为旧版微博配置项,已废弃(除非你能搞到旧版cookies),不用动。

可以在config放多个配置文件,只要按格式写就行,在scrapy_weiboSpider/config_path_file.py中设置你要启用的配置文件路径。 config_path_file.py中默认设置是 ./configs/n1_userWb_config.json ,用之前最好检查下,因为我老是把自己用的文件路径提交上来。

配置文件中,灰框内为不用动的,蓝框内为必填项,橙框内为选填功能项

1710668227549


不用动的部分

description:用来看的

id:用来确认启用哪个模式

基础配置

cookies_str:登录状态信息,没有这个只能获取到一页内容,cookies 获取

user_iduserid 获取


用户主页爬取配置

功能是爬取一个用户发过的所有微博

print_level:设为1的话会多一些输出内容,属于无关紧要的配置,反正日志里该有的都有

user_name:你要爬取的用户的用户名。不写也行,因为这个项影响的是文件保存位置,具体看结果文件那里的说明。

get_rwb_detail:是否获取源微博的详细信息,1获取,0不获取

time_limit:时间限制,只获取现在到所设定时间范围内的微博,有三种模式

​ 手动模式 - 字符串:填写yyyy-mm-dd hh-MM格式的字符串,例:"2024-01-01 00:00"

​ 手动模式 - 毫秒级时间戳,填写毫秒级时间戳,例:1710655039000

​ 自动模式:填写“auto”,该模式下,如果你之前用同样的配置运行过程序,程序会自动获取上次最新一条微博 的时间作为该配置项的值

get_comm_num:限制保存多少评论,设为 -1 就是保存所有评论。这个功能目前有点问题,可能会限制失败导致爬完所有评论,但是最近没时间修,将就用

wb_rcomm:爬取每条微博下的多少根评论

wb_ccomm:爬取每条根评论下的多少子评论

​ 若目标用户A转发了B的微博,B这条微博称为源微博(rwb)

rwb_rcomm:爬取每条源微博下的多少根评论

rwb_ccomm:爬取源微博每条根评论下的多少子评论




启动

环境配置

首先你电脑肯定得装了python

项目路径下pip install -r requirements.txt

redis

程序用到了redis来做进度记录和过滤,下载地址 https://github.com/tporadowski/redis/releases ,我用的版本是3.0.504。

解压后戳redis-server.exe,弹出右边的窗口就是启动成功了,每次运行程序前都要先启动这个。

1628613064721


启动程序

先按前面说的修改配置文件

改好后 项目路径下敲 scrapy crawl new_wb_spider

它就跑起来了,把它扔那该干啥干啥,别断网就行,啥时候想起来就看看它跑完没。



结果文件

结果文件在./file下的对应文件夹里

爬取用户主页的文件标识由user_id user_name time_range决定,

只设置了user_id时,文件标识为user_id,

设置了time_range时,时间范围添加在user_id后(x是不设结束时间)

设置了user_name时,用户名添加在user_id前

time_rangeuser_name都设置了,则两个都有

1628655283246

结果文件夹的内容:

1672024192551

假如你爬了A的微博主页,其中wb_result.json中为A发过的所有微博,r_wb_result.json中为A所有转发微博的源微博,如果你将get_rwb_detail设为0,则不会有r_wb_result.json,而是sr_wb_result.json。

结果文件示例

结果文件中各字段的含义

prefile中为过程文件。weibo是微博信息,rcomm是根评论信息,ccomm是子评论信息,程序结束时会整合到两个result文件中,运行结束后可以选择是否删除。

联系我

有问题的话我的邮箱是 [email protected],如果是程序出问题最好把日志一块发给我,日志在项目路径下的log文件夹,格式是 日期_序号.log,发最新的一份就行 如果要讨论,微信号Ishtar_Tang,备注从微博爬虫来的。

其他

程序并爬取用户主页时,首先请求这个页面 李镜合首页 ,一次请求可以获取到20条微博,这个页面足够获取到大多数微博的完整信息,可以直接进行解析。但超过140字的微博会被折叠,这种时候才会请求微博详情页,比如 李镜合的微博


不用再往下看了,这个上面有,直接在上面插表格感觉看着很不爽,所以上面插的图片链接,这是为了方便以后万一要修改留的表格备份。

文件中各字段含义

含义 类型
bid 微博bid,一条微博的唯一标识 str
t_bid 哪条微博转发了当前微博,只有r_wb_result中的此项不为空 str
weibo_url 该条微博链接 str
user_id 用户id str
user_name 用户名 str
content 微博正文 str
public_time 发表时间 str
public_timestamp 发表时间戳 int
share_scope: 可见范围 str
like_num 点赞数 int
forward_num 转发数 int
comment_num 评论数 int
is_original 是否为原创,原创为1,转发为0,快转为-1 int
links 微博正文中包含的链接 list,list中为str
img_list 图片链接列表 list,list中为str
video_url 视频链接 str
weibo_from 微博来源 str
article_url 文章链接 str
article_content 文章内容 str
remark 备注 str
r_href 如果是转发的微博,这里是源微博的url,否则空 str
r_weibo 如果是转发的微博,这里是源微博的简单信息,否则空 str
comments 评论信息列表 dict

comments下各字段含义

含义 类型
content 评论内容 str
user_name 评论人的名字 str
user_url 评论人主页链接 str
comment_date 评论时间 str
comment_type 直接回复微博的评论为root评论,评论下的回复为child评论 str
parent_comment child_comment是回复了哪条评论,root评论无parent_comment, str
like_num 点赞数 int
comment_img_url 评论中带的图片链接 str
link 评论中带的链接 str
chile_comm 子评论,即该条评论下的回复,子评论键值内容与父评论相同

weibo_spider-scrapy's People

Contributors

ishtartang avatar

Stargazers

 avatar DiDi avatar  avatar  avatar  avatar hilllll avatar MightZ avatar  avatar  avatar Yukang Liu avatar  avatar  avatar  avatar hd2wl avatar yixinmei avatar Bai Feng avatar Kingking avatar  avatar  avatar Alioth avatar  avatar Xiangqing Shen avatar

Watchers

beyoung avatar  avatar

weibo_spider-scrapy's Issues

configs文件夹缺少text.json

自己摸索着解决了,就是把scrapy_weiboSpider/config_path_file.py这个文件里的路径改成n1_userWb_config.json
我不太懂代码,不知道是我这边的问题还是作者忘记改

谢谢作者写出好用的工具,终于可以备份评论了 :)

获取ident一直失败

请问程序不停的打印出一下内容是哪里出了问题呢
“获取ident已经失败 5 次,如失败次数过多请检查网络,或尝试更新cookies�”
“获取ident已经失败 10 次,如失败次数过多请检查网络,或尝试更新cookies”
“获取ident已经失败 15 次,如失败次数过多请检查网络,或尝试更新cookies”

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.