NanmiCoder / NanmiCoder/MediaCrawler

运行时报错

Open
#601 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
65.3k
Forks
12.6k
PR merge metrics
No merged PRs in 30d

Description

⚠️ 提交前确认

  • 我已经仔细阅读了项目使用过程中的常见问题汇总
  • 我已经搜索并查看了已关闭的issues
  • 我确认这不是由于滑块验证码、Cookie过期、Cookie提取错误、平台风控等常见原因导致的问题

❓ 问题描述

相同的配置,一开始没有遇到这个问题,大致是第10次的时候出现了。随后一直都出现这个问题。
爬取关键词记录时,一开始没有问题,可以在shell中看到爬取的记录,
爬到一半,遇到这个报错,换了另一个账号登录,依然报这个错误。应该可以排除平台风控吧。
换用抖音的时候也没有遇到这个问题
现在没有继续排查问题的头绪。

🔍 使用场景

  • 目标平台: (如:小红书/抖音/微博等) 小红书
  • 使用功能: (如:关键词搜索/用户主页爬取等) 关键词搜索

💻 环境信息

  • 操作系统: windows 11
  • Python版本: 3.9.6
  • 是否使用IP代理: 否
  • 是否使用VPN翻墙软件:否
  • 目标平台(抖音/小红书/微博等): 小红书

📋 错误日志

2025-05-16 15:22:40 MediaCrawler INFO (core.py:366) - [XiaoHongShuCrawler.get_comments] Begin get note id comments 6731e4bb000000003c01d86b
Traceback (most recent call last):
  File "D:\workspace\crawler\MediaCrawler-main\main.py", line 66, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "D:\tools\anaconda3\envs\mediaCrawler\lib\asyncio\base_events.py", line 642, in run_until_complete
    return future.result()
  File "D:\workspace\crawler\MediaCrawler-main\main.py", line 56, in main
    await crawler.start()
  File "D:\workspace\crawler\MediaCrawler-main\media_platform\xhs\core.py", line 99, in start
    await self.search()
  File "D:\workspace\crawler\MediaCrawler-main\media_platform\xhs\core.py", line 179, in search
    await self.batch_get_note_comments(note_ids, xsec_tokens)
  File "D:\workspace\crawler\MediaCrawler-main\media_platform\xhs\core.py", line 359, in batch_get_note_comments
    await asyncio.gather(*task_list)
  File "D:\workspace\crawler\MediaCrawler-main\media_platform\xhs\core.py", line 374, in get_comments
    await self.xhs_client.get_note_all_comments(
  File "D:\workspace\crawler\MediaCrawler-main\media_platform\xhs\client.py", line 360, in get_note_all_comments
    await callback(note_id, comments)
  File "D:\workspace\crawler\MediaCrawler-main\store\xhs\__init__.py", line 129, in batch_update_xhs_note_comments
    await update_xhs_note_comment(note_id, comment_item)
  File "D:\workspace\crawler\MediaCrawler-main\store\xhs\__init__.py", line 162, in update_xhs_note_comment
    await XhsStoreFactory.create_store().store_comment(local_db_item)
  File "D:\workspace\crawler\MediaCrawler-main\store\xhs\xhs_store_impl.py", line 246, in store_comment
    await self.save_data_to_json(comment_item, "comments")
  File "D:\workspace\crawler\MediaCrawler-main\store\xhs\xhs_store_impl.py", line 215, in save_data_to_json
    save_data = json.loads(await file.read())
  File "D:\tools\anaconda3\envs\mediaCrawler\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "D:\tools\anaconda3\envs\mediaCrawler\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "D:\tools\anaconda3\envs\mediaCrawler\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

📷 错误截图

这是一开始:
Image
一开始没有问题,运行到一半的时候,控制台会卡住,然后输出一大段爬到的记录,输出完之后,就会报错如下:
Image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the traceback entry point in media_platform/xhs/core.py, then follow the comment-saving path through store/xhs/init.py to store/xhs/xhs_store_impl.py, especially save_data_to_json. Reproduce the Xiaohongshu keyword-search case and inspect the comments JSON read at the reported failure; done means comment collection no longer stops with JSONDecodeError and stored JSON remains readable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.