python环境下的selenium初步使用
2018-04-02 21:30
344 查看
selenium支持多种浏览器,我以windows环境下的chrome做演示。
chrome的默认安装路径应在C:\Program Files (x86)\Google中,如果文件夹移动到其他位置,使用时需改动selenium的源码,这里不做推荐。
网上下载chromedriver,放在C:\Program Files (x86)\Google\Chrome\Application目录下,并将此目录加到环境变量中。
打开python命令行,安装selenium,pip install selenium。
最原始代码如下:from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://www.baidu.com/")运行后浏览器可能会提示“Chrome正受到自动测试软件的控制”或者“ignore-certificate-errors”两个错误
修改代码如下:from selenium import webdriver
# 加启动配置
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
option.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
# 打开chrome浏览器
browser = webdriver.Chrome(chrome_options=option)
browser.get("https://www.baidu.com/")运行后浏览器会显示百度页面。
提示:
如果网址填写为“www.baidu.com” 浏览器会无响应,编译器会显示类似错误:
selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"}
必须改为“https://www.baidu.com/”格式
chrome的默认安装路径应在C:\Program Files (x86)\Google中,如果文件夹移动到其他位置,使用时需改动selenium的源码,这里不做推荐。
网上下载chromedriver,放在C:\Program Files (x86)\Google\Chrome\Application目录下,并将此目录加到环境变量中。
打开python命令行,安装selenium,pip install selenium。
最原始代码如下:from selenium import webdriver
browser = webdriver.Chrome()
browser.get("https://www.baidu.com/")运行后浏览器可能会提示“Chrome正受到自动测试软件的控制”或者“ignore-certificate-errors”两个错误
修改代码如下:from selenium import webdriver
# 加启动配置
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
option.add_experimental_option("excludeSwitches",["ignore-certificate-errors"])
# 打开chrome浏览器
browser = webdriver.Chrome(chrome_options=option)
browser.get("https://www.baidu.com/")运行后浏览器会显示百度页面。
提示:
如果网址填写为“www.baidu.com” 浏览器会无响应,编译器会显示类似错误:
selenium.common.exceptions.WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"}
必须改为“https://www.baidu.com/”格式
相关文章推荐
- python3 [爬虫入门实战]爬虫之selenium 安装设置与初步使用
- Selenium的运行环境不要使用python3
- Python+selenium环境搭建&初步实践
- Windows环境下使用python selenium 打开Firefox的问题总结
- python下初步使用selenium/phantomJS问题总结
- python3,pyCharm2016环境下Django框架搭建与初步使用
- Python Web 实战 - 搭建Django环境和初步使用
- 在s60上使用python的环境
- pydev 使用Eclipse搭建python开发环境
- 使用Python开发Android应用程序:第一节 在手机上配置Python运行环境
- 搭建Selenium的Python开发环境
- windows下使用gvim搭建简单的IDE编译环境(支持C/C++/Python等)
- 使用Aptana+Pydev构建Python开发环境(Django)
- 搭建Python Selenium自动化测试环境
- cherrypy安装使用,配置python环境变量
- 在django1.2+python2.7环境中使用send_mail发送邮件 推荐
- 使用Eclipse与Pydev搭建python开发环境
- Python中SQLite数据库使用初步
- 使用python3.2开发pyramid1.3(安装环境和初始项目)
- Linux环境下MySQL-python使用小记