惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threat Research - Cisco Blogs
Latest news
Latest news
Project Zero
Project Zero
TaoSecurity Blog
TaoSecurity Blog
Cyberwarzone
Cyberwarzone
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
T
Troy Hunt's Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AWS News Blog
AWS News Blog
Hacker News: Ask HN
Hacker News: Ask HN
S
Security @ Cisco Blogs
C
Cisco Blogs
Help Net Security
Help Net Security
I
Intezer
W
WeLiveSecurity
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
腾讯CDC
S
Secure Thoughts
MyScale Blog
MyScale Blog
Recorded Future
Recorded Future
G
GRAHAM CLULEY
L
LINUX DO - 热门话题
A
About on SuperTechFans
C
CXSECURITY Database RSS Feed - CXSecurity.com
IT之家
IT之家
J
Java Code Geeks
The Hacker News
The Hacker News
阮一峰的网络日志
阮一峰的网络日志
Scott Helme
Scott Helme
Recent Announcements
Recent Announcements
AI
AI
Cisco Talos Blog
Cisco Talos Blog
B
Blog RSS Feed
V
Vulnerabilities – Threatpost
C
Check Point Blog
Security Latest
Security Latest
S
SegmentFault 最新的问题
T
The Exploit Database - CXSecurity.com
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
M
MIT News - Artificial intelligence
T
The Blog of Author Tim Ferriss
Attack and Defense Labs
Attack and Defense Labs
PCI Perspectives
PCI Perspectives
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
Tailwind CSS Blog
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - pmh905001

爬虫-今日头条我的收藏-反爬虫分析(六) pycharm的没落,vs code的兴起 爬虫-今日头条我的收藏-增量式下载网页内容(五) 爬虫-今日头条我的收藏-增量式导入到Elastic Search(四) 今日头条源代块一行代码很长情况下的拖动问题 爬虫-今日头条我的收藏-增量式(二) openpyxl一个bug 爬虫-今日头条我的收藏(一) pystray被隐藏菜单项显示出来的问题 pyinstaller生成的exe程序使用使用默认程序打开execel文件 pyinstaller生成的exe文件的所在的工作目录问题 windows下python的keyboard库在锁屏之后再次登陆快捷键(热键)失效问题 pyinstaller 报错ImportError: No module named _bootlocale windows下gitbash 鼠标左键选中文字自动自行终止命令 ctrl+c ^C spring-security 如何使用用户名或邮箱登录 tomcat jndi context.xml的特殊字符转义问题 struts2的优缺点以及如何改造 jetty-maven-plugin 版本导致jetty启动失败问题 Eclipse下pom.xml的提示 Cannot access defaults field of Properties
爬虫-今日头条我的收藏-增量式导入到mongodb(三)
pmh905001 · 2023-12-20 · via 博客园 - pmh905001

背景:

  • 续接前文,当我们有了原始数据之后,自然会想如何利用这些数据。这些文件数据都是json格式,打开一个文本文件眼睛都要看花。所以想把这些数据导入到对应的数据库中,市面上几乎所有数据库都支持json格式存储。
  • 随着时间的推移,用户不断有新的收藏,这样就不断产生新的收藏文件。需要不断的导入到数据库中。
  • sqlite 3.38版本支持json格式。
  • mongodb本身就是nosql数据库中做的很好的。之前在公司曾经考虑把json数据存储到mongodb,可惜方案被否(当时数据存储已经选择了mysql,且mysql支持json格式)。可以利用这个机会学习mongodb

思路:

  • 先实现一个全量的数据导入mongodb。有多个原始文本文件记录了我的收藏信息,他们是倒序的。文本需要按照时间先后顺序依次导入。
  • 再增量导入到mongodb。需要在mongodb中找到最后一条数据的id,根据这个id从多个文本文件中找到具体的位置,继续导入。需要考虑到断点在文本文件中(导入到一半,用户终止了程序),也有可能在文本文件头部(正常导入)。

实现:

  • 代码实现在这里:https://github.com/pmh905001/myfavorite/blob/master/toutiao/import2mongodb.py

posted on 2023-12-20 16:11  pmh905001  阅读(64)  评论()    收藏  举报