0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ウェブ自動化のための軽量なSeleniumラッパー。

Last updated at Posted at 2025-03-16

ausrine

PyPI
License

ウェブ自動化のための軽量なSeleniumラッパーです。

ausrineは、Seleniumの機能を直感的で使いやすいAPIにラップすることで、ウェブ自動化タスクを簡素化するように設計されています。データのスクレイピング、ウェブアプリケーションのテスト、反復的なブラウザタスクの自動化など、ausrineは最小限のセットアップで合理化されたエクスペリエンスを提供します。

インストール

pipを使用してausrineをインストールします:

pip install ausrine

ausrineは、WebDriverの依存関係を自動的に管理するSelenium Managerを備えたselenium>=4.0.0を使用します。インストール以外に追加のセットアップは必要ありません。

使用方法

ausrineは、直感的なWebAutomationDriverクラスを提供することで、Seleniumによるウェブ自動化を簡素化します。以下は、Bing検索を実行する例です:

from ausrine import WebAutomationDriver
from ausrine.chrome import setup_webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

# Chrome WebDriverを初期化
driver = setup_webdriver()

# WebAutomationDriverインスタンスを作成
ausrine = WebAutomationDriver(driver)

# Bingに移動
ausrine.get("https://www.bing.com/?cc=jp")

# 検索ボックスを見つけ、「iphone」と入力してEnterキーを押す
ausrine.send_keys(by=By.NAME, value="q", text="iphone")
ausrine.send_keys(by=By.NAME, value="q", text=Keys.ENTER)

# ドライバーを終了
ausrine.quit()

executeを使用して一連のコマンドを実行することもできます:

sequences = [
    {"get": {"url": "https://www.bing.com/?cc=jp"}},
    {"send_keys": {"by": By.NAME, "value": "q", "text": "iphone"}},
    {"send_keys": {"by": By.NAME, "value": "q", "text": Keys.ENTER}},
]
ausrine = WebAutomationDriver(setup_webdriver())
ausrine.execute(sequences)
ausrine.quit()

エラー処理にはtry_executeを使用します:

sequences = [
    {"get": {"url": "https://www.bing.com/?cc=jp"}},
    {"send_keys": {"by": By.NAME, "value": "q", "text": "iphone"}},
    {"send_keys": {"by": By.NAME, "value": "q", "text": Keys.ENTER}},
]
ausrine = WebAutomationDriver(setup_webdriver())
error = ausrine.try_execute(sequences)
if error:
    print(f"エラーが発生しました: {error}")
else:
    print("実行が正常に完了しました")
ausrine.quit()

フォーム送信の例

以下は、ログインフォームを送信する例です:

from ausrine import WebAutomationDriver
from ausrine.chrome import setup_webdriver
from selenium.webdriver.common.by import By

# Chrome WebDriverを初期化
driver = setup_webdriver()

# WebAutomationDriverインスタンスを作成
ausrine = WebAutomationDriver(driver)

# ログインページに移動
ausrine.get("https://example.com/login")

# ユーザー名とパスワードを入力し、送信
ausrine.send_keys(by=By.ID, value="username", text="user")
ausrine.send_keys(by=By.ID, value="password", text="pass", password=True)
ausrine.submit(by=By.ID, value="login-btn")

# ドライバーを終了
ausrine.quit()

特徴

  • シンプルなAPI: 一般的なウェブタスクのためのgetclicksend_keyssubmitのような直感的なメソッド。
  • シーケンス実行: 堅牢な自動化のために、executeまたはtry_executeで複数のコマンドを連鎖させます。
  • カスタマイズ可能なWebDriver: setup_webdriverを介して、ヘッドレスモードやカスタムダウンロードディレクトリなどのオプションでChromeを設定します。
  • 軽量: 最小限の依存関係(Seleniumのみ)と焦点を絞った機能セット。

要件

  • Python >= 3.10
  • Selenium >= 4.0.0, < 5.0.0

ライセンス

このプロジェクトはMITライセンスの条件の下でライセンスされています。詳細はLICENSEファイルを参照してください。

貢献

貢献を歓迎します!詳細はCONTRIBUTING.mdファイルを参照し、GitHubリポジトリにIssueやプルリクエストを送信してください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?