Created
February 14, 2026 05:31
-
-
Save sumikawa/6eb8f5c164308c0dffa541598eeb27ec to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python3 | |
| # seleniumの必要なライブラリをインポート | |
| from selenium import webdriver | |
| from selenium.webdriver.common.by import By | |
| from selenium.webdriver.chrome.options import Options | |
| import time, os | |
| import urllib.request | |
| import urllib.parse | |
| from datetime import datetime | |
| import argparse | |
| home_dir = os.path.expanduser("~") | |
| directory_path = os.path.join(home_dir, '.selenium') | |
| chrome_options = Options() | |
| chrome_options.add_argument(f'user-data-dir={directory_path}') | |
| driver = webdriver.Chrome(options=chrome_options) | |
| driver.get('https://www.amazon.co.jp/your-orders/orders?timeFilter=year-2025') | |
| # time.sleep(360) | |
| height = 0 | |
| for _ in range(10): | |
| height += 800 | |
| driver.execute_script(f"window.scrollTo(0, {height});") | |
| time.sleep(1) | |
| initial_links = driver.find_elements(By.CLASS_NAME, "a-link-normal") | |
| receipt_links_hrefs = [] | |
| for link in initial_links: | |
| if "領収書等" in link.text: | |
| receipt_links_hrefs.append(link.get_attribute("href")) | |
| for href in receipt_links_hrefs: | |
| driver.get(href) # Navigate directly to the link | |
| time.sleep(3) # Wait for the page to load | |
| links2 = driver.find_elements(By.CLASS_NAME, "a-link-normal") | |
| for link2 in links2: | |
| if "印刷可能な注文概要" in link2.text: | |
| link2.click() | |
| time.sleep(3) | |
| driver.back() # Go back to the "領収書等" details page | |
| break | |
| time.sleep(3) # Wait on the "領収書等" details page | |
| driver.back() # Go back to the initial orders list page | |
| time.sleep(360) | |
| # Webドライバー の セッションを終了 | |
| driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment