library that scrapes the data from an account such as securities, bank
Project description
acctf
acctfは、銀行や証券会社をスクレイピングして入出金履歴、株や投信の保有数や取得価額、現在価格を取得するライブラリです。
下記の銀行等に対応しています。
銀行
- 住信SBIネット銀行
- 預金(ハイブリッド含む)(円のみ)
- 入出金履歴
- 代表口座
- ハイブリッド預金口座
- 目的別口座
その他
- WealthNavi(円表示のみ)
- 各資産クラス
利用方法
インストール
pip install acctf
playwright install chromium
uvを利用する場合:
uv add acctf
uv run playwright install chromium
注: v0.6.0 以降、ブラウザ自動化に Playwright を採用しています。 arm64 Linux (Raspberry Pi 5 など) では Chromium のみサポートされ、Firefox は動作しません。
サンプル
銀行
預金
from acctf.bank.sbi import SBI
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
sbi = SBI(page=page).login("<ユーザID>", "<パスワード>")
b = sbi.get_balance("7654321")
print(f"口座番号, 店舗, 残高, 口座タイプ")
print(f"{b[0].account_number}, {b[0].branch_name}, {b[0].value}, {b[0].deposit_type}")
sbi.logout()
browser.close()
口座番号, 店舗, 残高, 口座タイプ
7654321, 本店, 1234567.0, DepositType.ordinary
入出金履歴
住信SBIネット銀行はUIの変更に伴い、履歴のCSVをダウンロードしてデータを取得する方式です。
ブラウザコンテキストを accept_downloads=True で生成する必要があります。
また、ダウンロードしたCSVファイルはデータ取得後に削除されます。
from pathlib import Path
from acctf.bank.sbi import SBI, AccountName
from acctf.bank import CurrencyType
from playwright.sync_api import sync_playwright
from datetime import date
download_directory = str(Path.cwd()) + "/tmp"
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
# CSVダウンロードのため accept_downloads=True が必須
context = browser.new_context(accept_downloads=True)
page = context.new_page()
sbi = SBI(page=page).login("<ユーザID>", "<パスワード>")
hist = sbi.get_transaction_history(
"7654321",
date(2023, 12, 1),
date(2023, 12, 31),
download_directory=download_directory,
currency=CurrencyType.jpy,
account_name=AccountName.Representative, # 代表口座
)
hist += sbi.get_transaction_history(
"7654321",
date(2023, 12, 1),
date(2023, 12, 31),
download_directory=download_directory,
currency=CurrencyType.jpy,
account_name=AccountName.Hybrid, # ハイブリッド預金口座
)
print(f"日付, 取引内容, 金額")
for h in hist:
print(f"{h.date}, {h.content}, {h.value}")
sbi.logout()
browser.close()
その他
WealthNavi
from acctf.other.wealthnavi import WealthNavi
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
w = WealthNavi(page=page).login("<ユーザID>", "<パスワード>", "<TOTP>")
# Time-based One Time Passwordを設定していない場合
# w = WealthNavi(page=page).login("<ユーザID>", "<パスワード>")
print("資産クラス, 現在価格, 損益")
for h in w.get_valuation():
print(f"{h.name}, {h.value}, {h.pl_value}")
w.logout()
browser.close()
資産クラス, 現在価格, 損益
米国株(VTI), 123456.0, 12345.0
日欧株(VEA), 123456.0, 12345.0
新興国株(VWO), 123456.0, 12345.0
債券(AGG), 123456.0, 12345.0
金(GLD), 123456.0, 12345.0
金(IAU), 123456.0, 12345.0
不動産(IYR), 123456.0, 12345.0
現金, 123456.0, 0.0
arm64 環境について
Raspberry Pi 5 などの arm64 Linux 環境では、Playwright が公式に提供しているブラウザバイナリは Chromium のみ です。Firefox および branded Chrome は arm64 Linux では動作しません。
公式 Docker イメージ mcr.microsoft.com/playwright/python は linux/amd64 / linux/arm64 の multi-arch ビルドが提供されているため、Kubernetes クラスタ (arm64) 上でも追加設定なしに利用できます。Docker での実行サンプルは examples/ を参照してください。
v0.5.x からの移行
v0.6.0 で Selenium から Playwright へ移行しました。コンストラクタが driver= (Selenium WebDriver) から page= (Playwright Page) に変わります。
# v0.5.x (Selenium)
from selenium import webdriver
driver = webdriver.Chrome()
sbi = SBI(driver=driver).login(...)
# v0.6.0 (Playwright)
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
sbi = SBI(page=page).login(...)
timeout の単位が秒 (30) からミリ秒 (30000) に変わっています。
開発
このリポジトリは uv で依存関係を管理しています。
セットアップ
uv sync
uv run playwright install chromium
ビルド
uv build
dist/ 配下にホイール (.whl) と sdist (.tar.gz) が生成されます。
PyPIへの公開
uv publish
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file acctf-0.6.0.tar.gz.
File metadata
- Download URL: acctf-0.6.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60da07f0a69f14377ca42a8ee2fee407843e8f70d2e58ac52ffaa2543d93fd27
|
|
| MD5 |
14e68eeb1b100dff1aeb304f24b29844
|
|
| BLAKE2b-256 |
a8c988a55dfc5a737e1916005e500523a527462f2189141e0dd4aa9f40934df4
|
Provenance
The following attestation bundles were made for acctf-0.6.0.tar.gz:
Publisher:
release.yml on hirano00o/acctf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
acctf-0.6.0.tar.gz -
Subject digest:
60da07f0a69f14377ca42a8ee2fee407843e8f70d2e58ac52ffaa2543d93fd27 - Sigstore transparency entry: 1537133413
- Sigstore integration time:
-
Permalink:
hirano00o/acctf@b79008d1b4ceed8eece5a24f61481a2e72216998 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/hirano00o
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b79008d1b4ceed8eece5a24f61481a2e72216998 -
Trigger Event:
release
-
Statement type:
File details
Details for the file acctf-0.6.0-py3-none-any.whl.
File metadata
- Download URL: acctf-0.6.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c664c170c8662674bf62db294634031e2e8b9c7cbf2b3ad93ebac1e0a913020
|
|
| MD5 |
3c87bd3230fd88d30b21f9d17a2892ee
|
|
| BLAKE2b-256 |
04c2f8968e6c8300d18e16028d3aa1234299075f74e8ddc2f55735ded14a1576
|
Provenance
The following attestation bundles were made for acctf-0.6.0-py3-none-any.whl:
Publisher:
release.yml on hirano00o/acctf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
acctf-0.6.0-py3-none-any.whl -
Subject digest:
8c664c170c8662674bf62db294634031e2e8b9c7cbf2b3ad93ebac1e0a913020 - Sigstore transparency entry: 1537133494
- Sigstore integration time:
-
Permalink:
hirano00o/acctf@b79008d1b4ceed8eece5a24f61481a2e72216998 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/hirano00o
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b79008d1b4ceed8eece5a24f61481a2e72216998 -
Trigger Event:
release
-
Statement type: