需要自行准备 Reddit API 凭据供 PRAW 使用;完整用法已移到独立 mdBook 手册,README 不再包含全部参数说明;词云功能可能依赖额外 Python 库,README 未说明
URS
JosephLai241MIT更新放缓一条命令就能把 Reddit 的帖子、评论和用户数据批量抓取下来,导出成 CSV 或 JSON,方便做数据分析和存档。
Universal Reddit Scraper - A comprehensive Reddit scraping/archival command-line tool.
README 未给出安装命令,使用说明见 https://josephlai241.github.io/URSREADME 未说明
基于 PRAW 的 Reddit 抓取命令行工具,抓帖子、评论并做词频与词云分析
一条命令就能把 Reddit 的帖子、评论和用户数据批量抓取下来,导出成 CSV 或 JSON,方便做数据分析和存档。
核心能力
- 通过 PRAW 抓取 Subreddit、Redditor 和帖子评论
- 实时监听 Subreddit 或用户的新帖与新评论
- 对抓取结果生成词频统计
- 根据抓取结果生成词云
- 支持导出 CSV 并检查 PRAW 速率限制
容易踩的坑
- v3.4.0URS v3.4.0最新正式版2023-05-11 · 2023-05-11 14:46 UTC
Summary
This release contains code cleanup by upgrading the project structure to a
Poetryproject, and refactoring a compute-heavy bottleneck within this program in Rust, drastically improving performance.Changelog
Added
taisun- A Python module written in Rust that contains the depth-first search algorithm and associated data structures for structured comments scraping. This library will eventually contain additional code that handles compute-heavy tasks.- GitHub Actions Workflows
rust.yml- Format and lint Rust code.python.yml- Format and test Python code.manual.yml- Build and deploy themdBookmanual to GitHub Pages.
- A new user guide/manual built from
mdBook. - Added type hints to all
urs/code.
Changed
- Dates used in this program have been updated to use the ISO8601 timestamp format (
YYYY-MM-DD HH:MM:SS). - Docstrings have been updated from NumPy to reStructuredText format.
- Simplifying the
STYLE_GUIDE.md- The style is dictated byBlackandisortfor Python code, andrustfmtfor Rust. - Simplifying the
README.md- Most information previously listed there has been moved to the user guide/manual.
- Formatted every single Python file with
Blackandisort. - Upgraded/recorded new demo GIFs.
Deprecated
N/A
- v3.3.2URS v3.3.22021-07-22 · 2021-07-22 20:30 UTC
查看更新说明
Summary
This release fixes an open issue.
PRAW v7.3.0 changed the
Redditorobject'ssubredditattribute. This change breaks the Redditor scraper. It would be nice if all the tools worked as advertised.Full Changelog
Added
- Source code
- In
Redditor.py:- Added a new method
GetInteractions._get_user_subreddit()- extractssubredditdata from theUserSubredditobject into a dictionary.
- Added a new method
- In
- Tests
- In
test_Redditor.py:- Added
TestGetUserSubredditMethod().test_get_user_subreddit()to test the new method.
- Added
- In
Changed
- Source code
- In
Redditor.py:GetInteractions._get_user_info()calls the newGetInteractions._get_user_subreddit()method to set the Redditor'ssubredditdata within the main Redditor information dictionary.
- In
Version.py:- Incremented version number.
- In
README- Incremented PRAW badge version number.
- Source code
- v3.3.1URS v3.3.12021-07-03 · 2021-07-03 20:07 UTC
查看更新说明
Summary
- Introduced a new utility,
-t, which will display a visual tree of the current day's scrape directory by default. Optionally, include a different date to display that day's scrape directory. - Move CI providers from Travis-CI to GitHub Actions.
- Travis-CI is no longer free - there is now a free build cap.
- Minor code refactoring and issue resolution.
Full Changelog
Added
- User interface
- Added a new utility:
-t/--tree- display the directory structure of the current date directory. Or optionally include a date to display that day's scrape directory.
- Added a new utility:
- Source code
- Added a new file
Utilities.pyto theurs/utilsmodule.- Added a class
DateTreewhich contains methods to find and build a visual tree for the target date's directory.- Added logging when this utility is run.
- Added a class
- Added an additional Halo to the wordcloud generator.
- Added a new file
README- Added new "Utilities" section.
- This section describes how to use the
-t/--treeand--checkutility flags.
- This section describes how to use the
- Added new "Sponsors" section.
- Added new "Utilities" section.
- Tests
- Added
test_Utilities.pyunder thetest_utilsmodule.
- Added
Changed
- Source code
- Refactored the following methods within the
analyticsmodule:GetPath.get_scrape_type()GetPath.name_file()FinalizeWordcloud().save_wordcloud()- Implemented
pathlib'sPath()method to get the path.
- Implemented
- Upgraded all string formatting from old-school Python formatting (using the
%operator) to the superiorf-string. - Updated GitHub Actions workflow
pytest.yml.- This workflow was previously disabled. The workflow has been upgraded to test URS on all platforms (
ubuntu-latest,macOS-latest, andwindows-latest) and to send test coverage to Codecov after testing completes onubuntu-latest.
- This workflow was previously disabled. The workflow has been upgraded to test URS on all platforms (
- Refactored the following methods within the
README- Changed the Travis-CI badge to a GitHub Actions badge.
- Updated badge link to route to the workflows page within the repository.
- Changed the Travis-CI badge to a GitHub Actions badge.
- Tests
- Upgraded all string formatting from old-school Python formatting (using the
%operator) to the superiorf-stringin the following modules:test_utils/test_Export.pytest_praw_scrapers/test_live_scrapers/test_Livestream.py
- Refactored two tests within
test_Export.py:TestExportWriteCSVAndWriteJSON().test_write_csv()TestExportExportMethod().test_export_write_csv()
- Upgraded all string formatting from old-school Python formatting (using the
- Community documents
- Updated
PULL_REQUEST_TEMPLATE.md.- Removed Travis-CI configuration block.
- Updated
Deprecated
- Source code
- Removed
.travis.yml- URS no longer uses Travis-CI as its CI provider.
- Removed
- Introduced a new utility,
- v3.3.0URS v3.3.02021-06-15 · 2021-06-15 03:17 UTC
查看更新说明
Summary
- Introduced livestreaming tools:
- Livestream comments or submissions submitted within Subreddits.
- Livestream comments or submissions submitted by a Redditor.
Full Changelog
Added
- User interface
- Added livestream scraper flags:
-lr- livestream a Subreddit-lu- livestream a Redditor- Added livestream scrape control flags to limit stream exclusively to submissions (default is streaming comments):
--stream-submissions
- Added a flag
-v/--versionto display the version number.
- Added livestream scraper flags:
- Source code
- Added a new sub-module
live_scraperswithinpraw_scrapersfor livestream functionality:Livestream.pyutils/DisplayStream.pyutils/StreamGenerator.py
- Added a new file
Version.pyto single-source the package version. - Added a
gallery_dataandmedia_metadatacheck inComments.py, which includes the above fields if the submission contains a gallery.
- Added a new sub-module
README- Added a new "Installation" section with updated installation procedures.
- Added a new section "Livestreaming Subreddits and Redditors" with sub-sections containing details for each flag.
- Updated the Table of Contents accordingly.
- Tests
- Added additional unit tests for the
live_scrapersmodule. These tests are located intests/test_praw_scrapers/test_live_scrapers:tests/test_praw_scrapers/test_live_scrapers/test_Livestream.pytests/test_praw_scrapers/test_live_scrapers/test_utils/test_DisplayStream.pytests/test_praw_scrapers/test_live_scrapers/test_utils/test_StreamGenerator.py
- Added additional unit tests for the
- Repository documents
- Added a Table of Contents for
The Forest.md
- Added a Table of Contents for
Changed
- User interface
- Updated the usage menu to clarify which tools may use which optional flags.
- Source code
- Reindexed the
praw_scrapersmodule:- Moved the following files into the new
static_scraperssub-module:Basic.pyComments.pyRedditor.pySubreddit.py
- Updated absolute imports throughout the source code.
- Moved the following files into the new
- Moved
confirm_options(), previously located inSubreddit.pytoGlobal.py. - Moved
PrepRedditor.prep_redditor()algorithm to its own class methodPrepMutts.prep_mutts().- Added additional error handling to the algorithm to fix the
KeyErrorexception mentioned in the Issue Fix or Enhancement Request section.
- Added additional error handling to the algorithm to fix the
- Removed Colorama's
init()method from many modules - it only needs to be called once and is now located inUrs.py. - Updated
requirements.txt.
- Reindexed the
README- The "Exporting" section is now one large section and is now located on top of the "URS Overview" section.
- Tests
- Updated absolute imports for existing PRAW scrapers.
- Removed a few tests for
DirInit.pysince themake_directory()andmake_type_directory()methods have been deprecated.
Deprecated
- Source code
- Removed many methods defined in the
InitializeDirectoryclass inDirInit.py:LogMissingDir.log()create()make_directory()make_type_directory()make_analytics_directory()- Replaced these methods with a more versatile
create_dirs()method.
- Replaced these methods with a more versatile
- Removed many methods defined in the
- Introduced livestreaming tools:
- v3.2.1URS v3.2.12021-03-28 · 2021-03-28 04:53 UTC
查看更新说明
Release date: March 28, 2021
Summary
- Structured comments export has been upgraded to include comments of all levels.
- Structured comments are now the default export format. Exporting to raw format requires including the
--rawflag.
- Structured comments are now the default export format. Exporting to raw format requires including the
- Tons of metadata has been added to all scrapers. See the Full Changelog section for a full list of attributes that have been added.
Credentials.pyhas been deprecated in favor of.envto avoid hard-coding API credentials.- Added more terminal eye candy - Halo has been implemented to spice up the output.
Full Changelog
Added
- User interface
- Added Halo to spice up the output while maintaining minimalism.
- Source code
- Created a comment
Forestand accompanyingCommentNode.- The
Forestcontains methods for insertingCommentNodes, including a depth-first search algorithm to do so.
- The
Subreddit.pyhas been refactored and submission metadata has been added to scrape files:"author""created_utc""distinguished""edited""id""is_original_content""is_self""link_flair_text""locked""name""num_comments""nsfw""permalink""score""selftext""spoiler""stickied""title""upvote_ratio""url"
Comments.pyhas been refactored and submission comments now include the following metadata:"author""body""body_html""created_utc""distinguished""edited""id""is_submitter""link_id""parent_id""score""stickied"
- Major refactor for
Redditor.pyon top of adding additional metadata.- Additional Redditor information has been added to scrape files:
"has_verified_email""icon_img""subreddit""trophies"
- Additional Redditor comment, submission, and multireddit metadata has been added to scrape files:
subredditobjects are nested withincommentandsubmissionobjects and contain the following metadata:"can_assign_link_flair""can_assign_user_flair""created_utc""description""description_html""display_name""id""name""nsfw""public_description""spoilers_enabled""subscribers""user_is_banned""user_is_moderator""user_is_subscriber"
commentobjects will contain the following metadata:"type""body""body_html""created_utc""distinguished""edited""id""is_submitter""link_id""parent_id""score""stickied""submission"- contains additional metadata"subreddit_id"
submissionobjects will contain the following metadata:"type""author""created_utc""distinguished""edited""id""is_original_content""is_self""link_flair_text""locked""name""num_comments""nsfw"
- Additional Redditor information has been added to scrape files:
- Created a comment
- Structured comments export has been upgraded to include comments of all levels.
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
__ __ _ __ ____
/\ \/\ \/\`'__\/',__\
\ \ \_\ \ \ \//\__, `\
\ \____/\ \_\\/\____/
\/___/ \/_/ \/___/
Universal Reddit Scraper - A comprehensive Reddit scraping command-line tool written in Python.
Sponsors
Table of Contents
Contact
Whether you are using URS for enterprise or personal use, I am very interested in hearing about your use case and how it has helped you achieve a goal. Additionally, please send me an email if you would like to contribute, have questions, or want to share something you have built on top of it.
You can send me an email by clicking on the badge. I look forward to hearing from you!
Introduction
This is a comprehensive Reddit scraping tool that integrates multiple features:
- Scrape Reddit via
PRAW(the official Python Reddit API Wrapper)- Scrape Subreddits
- Scrape Redditors
- Scrape submission comments
- Livestream Reddit via
PRAW- Livestream comments submitted within Subreddits or by Redditors
- Livestream submissions submitted within Subreddits or by Redditors
- Analytical tools for scraped data
- Generate frequencies for words that are found in submission titles, bodies, and/or comments
- Generate a wordcloud from scrape results
Usage Overview
[-h]
[-e]
[-v]
[-t [<optional_date>]]
[--check]
[-r <subreddit> <(h|n|c|t|r|s)> <n_results_or_keywords> [<optional_time_filter>]]
[-y]
[--csv]
[--rules]
[-u <redditor> <n_results>]
[-c <submission_url> <n_results>]
[--raw]
[-b]
[--csv]
[-lr <subreddit>]
[-lu <redditor>]
[--nosave]
[--stream-submissions]
[-f <file_path>]
[--csv]
[-wc <file_path> [<optional_export_format>]]
[--nosave]
"Where’s the Manual?"
URS Manual
This README has become too long to comfortably contain all usage information for this tool. Consequently, the information that used to be in this file has been moved to a separate manual created with mdBook, a Rust command-line tool for creating books from Markdown files.
Note: You can also find the link in the About sidebar in this repository.
Demo GIFs
Here are all the demo GIFs recorded for URS.
Note: The
ndcommand isnomad, a moderntreealternative I wrote in Rust.
Subreddit Scraping

Redditor Scraping

Submission Comments Scraping

Livestreaming Reddit

Generating Word Frequencies

Generating Wordclouds

Checking PRAW Rate Limits

Displaying Directory Tree
