使用Python做一个脚本自动化机器人

一、前提

        安装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()

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值