Skip to main content

quickdriver

Overview - 概要

QuickDriver is a wrapper for Selenium. By controlling WebDriver through QuickDriver, you can easily implement processes such as browser automation and scraping.

quickdriverはSeleniumのラッパーです。QuickDriverを介してWebDriverを操作することで、ブラウザの自動操作、スクレイピングなどの処理を簡単に実装できます。

Installation - インストール

You can install quickdriver and all required dependencies from PyPI:

quickdriverとその実行に必要なライブラリは以下でインストールできます。

pip

pip install quickdriver

uv add quickdriver

Requirements - 必要条件

To run quickdriver, you need the following environment:

quickdriverの実行には、以下の環境が必要です。

  • Python 3.8 or higher
  • Libraries:
    • selenium (version 4.27.1 or higher)

Usage Example - 使用例

import os
import random
import time
import pandas as pd

from selenium import webdriver as wd
from quickdriver import QuickDriver

options = wd.ChromeOptions()
options.add_argument('--incognito') # secret mode
options.add_argument('--start-maximized') # maximize a window
options.add_experimental_option('prefs', {'profile.managed_default_content_settings.images': 2}) # Image loading disabled

CSV_PATH = 'classroom_info.csv'

with wd.Chrome(options=options) as driver:   
    d = QuickDriver(driver)
    
    d.go_to('https://www.foobarbaz1.jp')
    pref_urls =[d.attr('href', e) for e in d.ss('li.item > ul > li > a')]
    
    classroom_urls =[]
    total = len(pref_urls)
    for i, url in enumerate(pref_urls, 1):
        print(f'{i}/{total} pref_urls')
        if not d.go_to(url):
            continue
        time.sleep(random.uniform(1, 2))
        links = [d.attr('href', e) for e in d.ss('.school-area h4 a')]
        classroom_urls.extend(links)

    total = len(classroom_urls)
    for i, url in enumerate(classroom_urls, 1):
        print(f'{i}/{total} classroom_urls')
        if not d.go_to(url):
            continue
        time.sleep(random.uniform(1, 2))
        row = {
            'URL': driver.current_url,
            '教室名': d.attr('textContent', d.s('h1 .text01')),
            '住所': d.attr('innerText', d.s('.item .mapText')),
            '電話番号': d.attr('textContent', d.s('.item .phoneNumber')),
            'HP': d.attr('href', d.s('a', d.next(d.s_re('th', 'ホームページ')))),
        }
        pd.DataFrame([row]).to_csv(
            CSV_PATH, 
            mode='a', 
            index=False, 
            header=not os.path.exists(CSV_PATH),
            encoding='utf-8-sig'
        )

Basic Usage - 基本的な使い方

QuickDriver Class

The quickdriver module consists of a single class: QuickDriver. This class wraps a Selenium WebDriver instance, providing convenient methods for interacting with web pages.

quickdriverモジュールは、QuickDriverクラス1つによって構成されています。QuickDriverクラスは、WebDriverのインスタンスを受け取ってSeleniumの処理をラップします。

d = QuickDriver(driver)

Methods

The QuickDriver class provides the following instance methods:

QuickDriverクラスは、以下のインスタンスメソッドによって構成されています。

1. ss

Get multiple web elements as a list using a CSS selector. Returns an empty list if no elements are found. If a WebElement is passed as the second argument, the search is performed within that element's DOM subtree.

セレクタで複数のWeb要素をリストで取得します。存在しない場合は空のリストを返します。第二引数にWeb要素を渡すと、その要素のDOMサブセットからの取得となります。

elems = d.ss('li.item > ul > li > a')

2. s

Get a single web element using a CSS selector. If more than one element satisfies the condition, only the first one is returned. Returns None if no element is found. If a WebElement is passed as the second argument, the search is performed within that element's DOM subtree.

セレクタでWeb要素を取得します。条件を満たす要素が複数ある場合、最初の一つだけが返されます。存在しない場合はNoneを返します。第二引数にWeb要素を渡すと、その要素のDOMサブセットからの取得となります。

elem = d.s('h1 .text01')

3. ss_re

Get multiple web elements as a list using a CSS selector and a regular expression to match the element's textContent. Returns an empty list if no elements are found. If a WebElement is passed as the third argument, the search is performed within that element's DOM subtree.

セレクタと、textContentに対する正規表現マッチングで複数のWeb要素をリストで取得します。存在しない場合は空のリストを返します。第三引数にWeb要素を渡すと、その要素のDOMサブセットからの取得となります。

elems = d.ss_re('li.item > ul > li > a', r'店\s*舗')

4. s_re

Get a single web element using a CSS selector and a regular expression to match the element's textContent. If more than one element satisfies the condition, only the first one is returned. Returns None if no element is found. If a WebElement is passed as the third argument, the search is performed within that element's DOM subtree.

セレクタと、textContentに対する正規表現マッチングでWeb要素を取得します。条件を満たす要素が複数ある場合、最初の一つだけが返されます。存在しない場合はNoneを返します。第三引数にWeb要素を渡すと、その要素のDOMサブセットからの取得となります。

elem = d.s_re('table tbody tr th', r'住\s*所')

5. attr

Get the value of an attribute from a web element.

Web要素から任意の属性値を取得します。

text = d.attr('textContent', elem)

6. next

Get the next sibling element of a web element.

渡されたWeb要素の弟要素を取得します。

next_elem = d.next(elem)

7. go_to

Navigate to the specified URL.

指定したURLに遷移します。

d.go_to('https://foobarbaz1.com')

8. click

After removing the target attribute of the specified web element, the click event is fired.

指定したWeb要素のtarget属性を削除した後、clickイベントを発生させます。

d.click(elem)

9. switch_to

Switch the driver's focus to the specified iframe element.

指定したiframe要素内に制御を移します。

d.switch_to(iframe_elem)

10. scroll_to_view

Scroll the page to bring the specified web element into view.

指定したWeb要素をスクロールして表示します。

d.scroll_to_view(elem)

License - ライセンス

MIT

Metadata

Release files for quickdriver 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quickdriver 3.0.1
File Size Uploaded Provenance Actions
quickdriver-3.0.1.tar.gz 19.3 kB Without provenance Details for quickdriver-3.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quickdriver 3.0.1
File Interpreter ABI Platform Actions
quickdriver-3.0.1-py3-none-any.whl Python 3 none any Details for quickdriver-3.0.1-py3-none-any.whl

Total release size: 25.4 kB

Release files / quickdriver-3.0.1.tar.gz

Download URL quickdriver-3.0.1.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
43128cc1ef1df5e80e5a8166a3ea4e22b352a029514ee7af3336d8e18b91ece8
BLAKE2b-256 checksum
How to use checksums
e72c5c6b612e71b4270d55ff4f6584cc8224883f4e0d825b55c0da266e39ef1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Release files / quickdriver-3.0.1-py3-none-any.whl

Download URL quickdriver-3.0.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a76073663be64218ea03645058f82485b174f579de2a298df9f3937c23c046af
BLAKE2b-256 checksum
How to use checksums
c8a76ffdfd2a3cfab25ce2c1dd9a26dff13a99d156734f366bfebe0a7aa63752
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Security for quickdriver 3.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page