python的浏览器操作-selenium版本4更新操作

文章介绍了如何获取Chrome浏览器的版本信息,下载对应版本的chromedriver,设置远程调试端口,并提供了使用Python的Selenium库进行自动化测试的代码示例,强调了关闭浏览器窗口和正确配置浏览器选项的重要性。
Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

1.获取操作浏览器地址:
"C:\Program Files\Google\Chrome\Application\chrome.exe"

2.浏览器输入:chrome://version/,获取对应版本号

112.0.5615.50 (正式版本) (64 位) (cohort: Stable Installs & Version Pins) 

3.下载驱动器版本

http://chromedriver.storage.googleapis.com/index.html

4.把驱动解压,获取驱动地址

5.0.特别注意点:运行前把执行的浏览器窗口全部关闭

5.0.窗口关闭

5.0.关闭

5.1.使用原来插件的运行cmd运行命令:

"C:\Program Files\Google\Chrome\Application\chrome.exe"  --flag-switches-begin --flag-switches-end --remote-debugging-port=9226

5.2.使用新的环境,cmd命令

"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9226 --user-data-dir="D:\user-chrome"

6.查看是否运行:

# 查看所有进程
tasklist |findstr chrome*

# 查看进程的网络状态
netstat -ano|findstr "9226"

7.直接上python命令

# 下载浏览器对应版本的chromedriver.exe
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service


def browser_now_05():
    # 启动115
    options_01 = Options()
    # chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:29887")
    # service_01 = Service = r"E:\down\chromedriver_win32_3_112.0.5615.49\chromedriver.exe"
    options_01.add_experimental_option("debuggerAddress", "127.0.0.1:9226")
    options_01.binary_location = r'C:\Users\用户名\AppData\Local\115Chrome\Application\115chrome.exe'
    # win32_2_83
    service_path = r"E:\down\chromedriver_win32_2_83.0.4103.39\chromedriver.exe"
    service_01 = Service(service_path)
    driver = webdriver.Chrome(service=service_01, options=options_01)
    driver.get('https://www.youkuaiyun.com/')
    # driver.get('https://baidu.com/')
    print(driver.title)


if __name__ == "__main__":
    browser_now_05()

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值