一、前提

        安装ChromeDriver,有了这个驱动才能与Google Chrome浏览器进行交互

下载地址:Chrome for Testing availability (googlechromelabs.github.io)

https://storage.googleapis.com/chrome-for-testing-public/128.0.6613.84/win64/chromedriver-win64.zip

把链接中的128.0.6613.84替换为你谷歌浏览器的版本就可以

二、添加Python脚本

from selenium import webdriver  
from selenium.webdriver.chrome.service import Service  
from selenium.webdriver.chrome.options import Options  
from selenium.webdriver.firefox.service import Service as FirefoxService  
from selenium.webdriver.firefox.options import Options as FirefoxOptions  
  
  
def open_browser_with_selenium(url, browser_type='chrome'):  
    if browser_type.lower() == 'chrome':  
        options = Options()  
        options.add_argument("--start-maximized")  # 最大化窗口  
        service = Service(r"E:\chrome_driver\chromedriver-win64\chromedriver-win64\chromedriver.exe")  # 替换为你的chromedriver路径  
        driver = webdriver.Chrome(service=service, options=options)   
    else:  
        raise ValueError("Unsupported browser type")  
    try:  
        driver.get(url)   
        return driver  
    finally:  
        # driver.quit()  
        pass  
  
  
if __name__ == "__main__":  
    browser_type = "chrome"  # 或者 "firefox"  
    open_url = "https://hao.360.com/?src=lm&ls=n7c0cb2399c"  # 替换为你要打开的网址  
    driver = open_browser_with_selenium(open_url, browser_type)   
    driver.quit()

 

 

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐