Python+selenium
来源:互联网 发布:php超市会员管理系统 编辑:程序博客网 时间:2024/05/05 07:18
Selenium 初次使用
感觉这个标题有点low。最近看了一个同事写的一个脚本可以控制网页的输入,个人感觉很有意思,决定学习学习。以下就是学习的过程。
1. 脚本环境,这是一个亘古不变的话题,工欲善其事,必先利其器。
a. Python27 的安装:这个我想网上太多的帖子告知你如何安装和设置,我就不多说了。我是基于windows的 eclipse+pydev
b. 下载Chromedriver.exe
地址:http://chromedriver.storage.googleapis.com/index.html
下载后安装到Chrome 目录
c. selenium 库 : 首先要安装setuptools,这样你就能用easy_install来安装pip(python的包管理工具。同时要把Scripts 路径加入到系统路径中。pip安装好后,就可以使用命令“pip install -U selenium” 安装你的selenium库了。
pip 安装 http://www.cnblogs.com/wu-wenmin/p/4250330.html
下载selenium
如果你以前安装过,执行命令或出现下面的某个提示:
如果你想重新安装,你需要清除 pip 的cache
Windows 下 路径 :%LocalAppData%\pip\Cache
另外
Linux and Unix
~/.cache/pip # and it respects the XDG_CACHE_HOME directory.
OS X
~/Library/Caches/pip
- 简单的实例
from selenium import webdriver import time browser = webdriver.Chrome(executable_path='C:/Users/eyaozng/AppData/Local/Google/Chrome/Application/chromedriver.exe')browser.get(r'https://www.baidu.com')browser.find_element_by_id("kw").send_keys("python")browser.find_element_by_id("su").click() time.sleep(5)
3 碰到的问题
a. Error “selenium.common.exceptions.WebDriverException: Message: ‘Application’ executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home”
原因:在断点调试后,发现是executeable_path 没有加“chromedriver.exe”
b. Chromedriver.exe has stopped working
调试窗口报 “socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host”
原因:在查看多个网站后,发现是由于chromesdriver 的版本与Chrome 版本不匹配导致的。
你首先需要知道chrome 的版本,可以使用在Chrome地址框内使用 ”chrome://version/“
然后到Chromedriver下载的服务器里找对应的version.你可以查看每个版本的notes.txt,它会告知你Chromedriver支持那个Chrome版本。
在这里我要使用ChromeDriver v2.32,由于我的Chrome是v59的。
c. 网页不能一直存在
原因:待续
- 目前的结果
能自动启动Chrome 和打开指定的网页和查询一些信息。
如下图:
- Selenium python
- python selenium
- python+selenium
- python + selenium
- Python Selenium
- python selenium
- Python selenium
- python+selenium
- selenium-python
- Python selenium
- Python+selenium
- Python+selenium
- python+selenium
- Python selenium
- python selenium
- Python+selenium
- python中使用selenium
- Python + Selenium环境搭建
- 基础dfs搜索讲解
- 大型分布式网站架构设计与实践 第三章
- HDU 2112 HDU Today(最短路)
- caffe 与 cuda 版本的问题
- deepmind_lab 运行文件bspc 依赖的东西如下
- Python+selenium
- 最速下降算法-matlab源码
- Parallels Desktop13 for Mac(PD虚拟机) V13.2.0中文破解版
- tomact环境
- DLIB在嵌入式上编译总结
- linux中shell变量$#,$@,$0,$1,$2等的含义解释
- 程序设计入门3 韩信点兵问题
- html 文字、图片水平无限滚动
- JDK1.5新特性之---增强for循环