Created
February 4, 2026 11:31
-
-
Save supertask/e5c52043afc4cfe97f9f5bdafd2b84da to your computer and use it in GitHub Desktop.
Kindleの書籍を全部スクショするスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyautogui | |
| import time | |
| import random | |
| import os | |
| # | |
| # Setting | |
| # | |
| book_dirs = [ | |
| "./book_origin/real_state_investment/the_millionaire_booklet/", | |
| "./book_origin/investment/daiboucho_seicho_toshi_waku_de_1_okuen/", | |
| "./book_origin/investment/waga_toshijutsu/", | |
| "./book_origin/investment/kabu_de_katsu_Peter_Lynch/", | |
| "./book_origin/investment/economic_indicators_Emin/", | |
| "./book_origin/investment/the_intelligent_investor_Benjamin_Graham/", | |
| "./book_origin/investment/ten_bugger_small_stock/", | |
| "./book_origin/investment/ten_bagger_by_toilet_smartphone/", | |
| "./book_origin/future/singularity_is_near/", | |
| "./book_origin/future/singularity_is_nearer/", | |
| ] | |
| book_dir = book_dirs[0] | |
| # ページ送りの方向設定 | |
| # "right" : 右キー(通常の読書) | |
| # "left" : 左キー(逆方向読書) | |
| # "up" : 上キー(縦スクロール) | |
| # "down" : 下キー(縦スクロール) | |
| direction = "right" # デフォルトは右キー | |
| # Kindleアプリがアクティブなウィンドウになっていることを確認 | |
| wait_seconds = 8 | |
| for i in range(wait_seconds): | |
| print(wait_seconds - i) | |
| time.sleep(1) # 8秒間待ってKindleアプリを開く時間を確保 | |
| if not os.path.exists(book_dir): | |
| os.mkdir(book_dir) | |
| #skip_offset_index = 0 | |
| #skip_offset_index = 217 | |
| skip_offset_index = 0 | |
| # キーの決定 | |
| press_button = direction | |
| screen_width, screen_height = pyautogui.size() | |
| screenshot_width = screen_width | |
| shot_rate = 0.9 | |
| screenshot_height = int(screen_height * shot_rate) | |
| screenshot_offset_y = int(screen_height * ((1 - shot_rate) / 2)) | |
| screenshot_width = screen_width | |
| screenshot_height = int(screen_height * 0.9) # スクリーンショットのサイズを計算(ここでは幅100%、高さ90%) | |
| for i in range(700): # 10ページ分スクリーンショットを取る | |
| screenshot_index = i | |
| screenshot = pyautogui.screenshot(region=(0, screenshot_offset_y, screenshot_width, screenshot_height)) | |
| screenshot.save(os.path.join(book_dir, f'screenshot_{screenshot_index}.png')) # スクリーンショットを保存 | |
| pyautogui.press(press_button) # 右矢印キーを押してページを進める | |
| time.sleep(random.uniform(0.8, 1)) # 0.3秒から0.8秒のランダムな時間で待つ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment