Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

YouTube Watch History Scraper

鑒於Google takeout有匯出資料不完整的BUG,製作一個土法煉鋼的爬蟲工具,能夠批次擷取 Google myactivity YouTube 觀看紀錄,並將資料儲存為 JSON 檔案。

目前僅支援Windows Edge瀏覽器 + Google繁體中文介面使用,其他平台一律沒測試過。

有任何問題與建議都可以在issue上通知我。

使用方式

1. 安裝套件

pip install selenium webdriver-manager

2. 取得 cookies

  • 以Chrome瀏覽器插件(如 Get cookies.txt LOCALLY)匯出此網頁 myactivity.google.com 的 cookies,存為 myactivity.google.com_cookies.txt

3. 執行爬蟲

python watch-history-scraper.py
or
python watch-history-scraper.py --start-date 2025/06/27 --end-date 2025/06/20 --output my_output.json
  • --start-date:爬取的起始日期(格式:YYYY/MM/DD),預設將從"今天"開始爬取
  • --end-date:爬取的停止日期(包含)(格式:YYYY/MM/DD),預設將會爬取到無資料為止
  • --output:輸出檔案名稱,預設為 youtube_watch_history.json

4. 自動開啟瀏覽器並登入

  • 執行時會自動開啟瀏覽器,請確認Google帳號透過Cookie登入成功,程式會在短暫停頓後開始執行。
  • 執行期間網頁會自動滾動,請不要進行觸碰與控制網頁,有機率爬不到資料。

輸出格式

每一筆紀錄都會已以下格式儲存

{
    "header": "YouTube",
    "title": "<影片標題>",
    "titleUrl": "https://www.youtube.com/watch?v=<video_id>",
    "subtitles": [
      {
        "name": "<頻道名稱>",
        "url": "https://www.youtube.com/channel/<channel_id>"
      }
    ],
    "time": "YYYY-MM-DDTHH:MM:SSZ"
    "products": ["YouTube"],
    "activityControls": ["YouTube watch history"]
}

注意事項

  • 本工具僅供個人備份與學術研究,請勿用於商業或違反 Google 條款之用途。
  • 若遇到 Google 反爬蟲,建議適當調整等待時間。

Made by Haha4ni

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages