selenium 安装及使用

  1. Python 安装: pip install selenium

  2. Mac 安装 chromedrive: brew install chromedriver,此时本机 Chrome 版本为 123.0.6312.107(正式版本) (arm64)

    image-20240407171451713

  3. 测试可用性,如果能打开浏览器并进入对应网页即为可用

    1
    2
    3
    4
    5
    6
    7
    8
    9
    from selenium import webdriver 
    from selenium.common.exceptions import WebDriverException
    dirver = webdriver.Chrome()
    dirver.get('https://www.baidu.com')
    try:
    while True:
    dirver.title
    except WebDriverException:
    pass