博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python selenium chrome 环境配置
阅读量:5892 次
发布时间:2019-06-19

本文共 3969 字,大约阅读时间需要 13 分钟。

Python selenium chrome 环境配置一、参考文章:    1. 记录一下python easy_install和pip安装地址和方法        http://heipark.iteye.com/blog/1916758    2. selenium + python自动化测试环境搭建        http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html    3. Python-selenium-Firefox-chrome-IE问题解决方法        http://blog.csdn.net/lcm_up/article/details/38302143    4. ChromeDriver - WebDriver for Chrome Getting started        https://sites.google.com/a/chromium.org/chromedriver/getting-started二、Windows PowerShell    1. 【win】键    2. 键入:Windows PowerShell + 【Enter】键三、Python setuptools 18.4 安装:    1. download:https://pypi.python.org/pypi/setuptools    2. 跳到ez_setup.py所在的目录    3. python .\ez_setup.py四、Python pip 7.1.2 安装:    1. download:https://pypi.python.org/pypi/pip#downloads    2. 跳到解压出来的目录下的setup.py所在的目录    3. python setup.py install五、Python selenium 2.48.0 安装:    1. download:https://pypi.python.org/pypi/selenium    2. 跳到解压出来的目录下的setup.py所在的目录    3. python setup.py install六、chrome driver    1. download:http://chromedriver.storage.googleapis.com/index.html?path=2.20/    2. 解压拷贝文件到:D:\python2_7\chromedriver_win32\chromedriver.exe    3. 创建一个chrome浏览器实例:        driver = webdriver.Chrome('D:\python2_7\chromedriver_win32\chromedriver') ##可以替换为IE(), FireFox()七、Test Demo(请确保能访问Google):    #!/usr/bin/python    # -*- coding: utf-8 -*-        import os    from selenium import webdriver    from selenium.common.exceptions import TimeoutException    from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0    import time        # Create a new instance of the browser driver    driver = webdriver.Chrome('D:\python2_7\chromedriver_win32\chromedriver')  ##可以替换为IE(), FireFox()        # go to the google home page    driver.get("http://www.google.com")        # find the element that's name attribute is q (the google search box)    inputElement = driver.find_element_by_name("q")        # type in the search    inputElement.send_keys("Cheese!")        # submit the form. (although google automatically searches now without submitting)    inputElement.submit()        # the page is ajaxy so the title is originally this:    print driver.title        try:        # we have to wait for the page to refresh, the last thing that seems to be updated is the title        WebDriverWait(driver, 10).until(lambda driver : driver.title.lower().startswith("cheese!"))            # You should see "cheese! - Google Search"        print driver.title        finally:            #driver.quit()      # 当前使用 driver.quit()会导致如下错误        #   Traceback (most recent call last):        #   File "E:/python/Spider/Spider.py", line 39, in 
# driver.quit() # File "D:\python2_7\install\lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 88, in quit # self.service.stop() # File "D:\python2_7\install\lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 111, in stop # url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port) # File "D:\python2_7\install\lib\urllib2.py", line 126, in urlopen # return _opener.open(url, data, timeout) # File "D:\python2_7\install\lib\urllib2.py", line 397, in open # response = meth(req, response) # File "D:\python2_7\install\lib\urllib2.py", line 510, in http_response # 'http', request, response, code, msg, hdrs) # File "D:\python2_7\install\lib\urllib2.py", line 435, in error # return self._call_chain(*args) # File "D:\python2_7\install\lib\urllib2.py", line 369, in _call_chain # result = func(*args) # File "D:\python2_7\install\lib\urllib2.py", line 518, in http_error_default # raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) # urllib2.HTTPError: HTTP Error 404: Not Found driver.close()

 

转载于:https://www.cnblogs.com/zengjfgit/p/4913600.html

你可能感兴趣的文章
在 IIS 下添加 FLV 类型文件的支持
查看>>
java线程学习3——线程的停止
查看>>
穿过任意防火墙NAT的远程控制软件TeamViewer
查看>>
PIX防火墙基本特性:失效处理机制和冗余-原理与实验
查看>>
域环境内部署Bginfo来统计用户计算机信息
查看>>
nagios短信报警(飞信fetion20080522004-linrh4)
查看>>
【Android游戏开发之六】在SurfaceView中添加组件!!!!并且相互交互数据!!!!...
查看>>
创建实体类使用Hibernate
查看>>
异常处理汇总-开发工具
查看>>
[LeetCode] Excel Sheet Column Number 求Excel表列序号
查看>>
通过浏览器直接打开Android应用程序
查看>>
MVC调用SVC无法找到资源解决问题
查看>>
div加jquery实现iframe标签的功能
查看>>
解决Yapi 插件运行不支持文件上传的问题解决
查看>>
Windows路由表详解
查看>>
MySQL从库记录binlog日志出错一例
查看>>
2015年度扯淡
查看>>
phpcms2008列表页模板与内容页模板list.html show.html
查看>>
Java程序员从笨鸟到菜鸟之(八十四)深入浅出Ajax
查看>>
GNS3全面详解系列-GNS3的前世今生
查看>>