python 通过selenium调用chrome浏览器

更新selenium

pip install -U selenium

下载浏览器和对应的驱动

Chrome for Testing availability

一般选稳定版本的,我是windows的就下win64的,

下载两个zip包后,把chromedriver.zip中的exe解压缩放到chrome_win64文件夹中

复制代码
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time

chrome_driver_path = r'.\chrome\chrome-win64\chromedriver.exe'

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--ignore-ssl-errors')
chrome_options.add_argument('--allow-insecure-localhost')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--enable-unsafe-swiftshader")
chrome_options.add_argument("--disable-save-password-bubble")
chrome_options.add_argument("--disable-password-manager-reauthentication")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)

service = Service(chrome_driver_path)
driver = webdriver.Chrome(service=service, options=chrome_options)

# 打开百度
driver.get("https://www.baidu.com")

time.sleep(5)
driver.quit()
# 第二次:重新启动并打开新浪
driver = webdriver.Chrome(service=service, options=chrome_options)
driver.get("https://www.sina.com.cn")
time.sleep(5)
driver.quit()
相关推荐
nn_(nana)21 小时前
修改文件权限--- chmod ,vi/vim,查看文件内容,yum-软件包管理器,systemctl管理系统服务
前端
烛阴1 天前
从零开始掌握C#核心:变量与数据类型
前端·c#
han_1 天前
前端高频面试题之Vuex篇
前端·vue.js·面试
qq_415216251 天前
vue3搭建项目yarn+vue3+webpack+less+element-plus
前端·webpack·less
天天向上10241 天前
VueUse的使用
前端·vue.js·vscode
猪猪拆迁队1 天前
前端图形引擎架构设计:双引擎架构设计
前端·后端·架构
宋辰月1 天前
学习react第三天
前端·学习·react.js
bug总结1 天前
更新原生小程序封装(新增缓存订阅)完美解决
前端·缓存·小程序
5335ld1 天前
后端给的post 方法但是要求传表单数据格式(没有{})
开发语言·前端·javascript·vue.js·ecmascript
二川bro1 天前
第33节:程序化生成与无限地形算法
前端·算法·3d·threejs