打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Python Selenium示例 - 启动不同浏览器

一、启动firefox浏览器

不需要下载任何驱动,原生支持firefox,但要注意firefox浏览器的版本,如果出现启动firefox失败的情况,请降低或升级firefox版本。

1、firefox安装在默认路径,启动代码如下:

# -*- coding:utf-8 -*-

from selenium import webdriver

driver=webdriver.Firefox()

# 注意http不可以省略
url='http://www.baidu.com'
      
driver.get(url)

driver.close()

2、指定firefox的安装路径启动,代码如下:

# -*- coding:utf-8 -*-

from selenium import webdriver

import os

# firefox 实际安装路径

ffdriver = "C:\\Program Files (x86)\\\Mozilla Firefox\\firefox.exe"

os.environ["webdriver.firefox.driver"] = ffdriver

driver = webdriver.Firefox(ffdriver )

# 注意http不可以省略
url='http://www.baidu.com'
      
driver.get(url)

driver.close()

二、启动google浏览器

需要下载相应的驱动,下载地址:

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

参考代码如下:

# -*- coding:utf-8 -*-

from selenium import webdriver

import os

# chromedriver.exe  实际安装路径, 笔者这里放置在C盘根目录

googledriver = "C:\\chromedriver.exe"

os.environ["webdriver.chrome.driver"] = googledriver

driver = webdriver.Chrome(googledriver)

# 注意http不可以省略
url='http://www.baidu.com'
      
driver.get(url)

driver.close()

三、启动IE浏览器

需要下载相应的驱动,下载地址:

http://selenium-release.storage.googleapis.com/index.html

参考代码如下:

# -*- coding:utf-8 -*-

from selenium import webdriver

import os

# iedriver.exe  实际安装路径, 笔者这里放置在C盘根目录

iedriver = "C:\\iedriver.exe"

os.environ["webdriver.ie.driver"] = iedriver

driver = webdriver.Chrome(iedriver)

# 注意http不可以省略
url='http://www.baidu.com'
      
driver.get(url)

driver.close()

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
用python selenium 自动化操作浏览器
WebDriver入门及提高
在Python Selenium中为Chrome和Firefox浏览器开启headless模式 | 李辉的个人网站
selenium:禁止加载图片和cookies使用
Selenium WebDriver + Python 环境配置
Selenium框架学习教程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服