from __future__ import annotations

from urllib.parse import quote_plus

from selenium.webdriver.support.ui import WebDriverWait

from src.driver_factory import create_webdriver


def run(*, keyword: str = "runoob") -> str:
    driver = create_webdriver()
    try:
        # 直接打开搜索结果页，降低首页弹窗/策略页对自动化操作的影响。
        driver.get(f"https://www.bing.com/search?q={quote_plus(keyword)}")

        WebDriverWait(driver, 15).until(lambda d: keyword.lower() in d.title.lower())
        return driver.title
    finally:
        driver.quit()


def main() -> None:
    print(run())


if __name__ == "__main__":
    main()
