Chinaunix首页 | 论坛 | 博客
  • 博客访问: 44891
  • 博文数量: 9
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-12 17:58
个人简介

熬着熬着,让时间熬成想要的那个自己,一个美丽的人。

文章分类

全部博文(9)

文章存档

2016年(1)

2014年(7)

2013年(1)

分类: Python/Ruby

2016-03-31 19:31:03

系统:OS X Capitan (version:10.11)

Python2.7.10: 系统自带
    终端输入python --version 可以查看版本号。

Selenium:
    用命令安装
    sudo easy_install selenium
    在用 brew install selenium的时候检测出来是brew install selenium-server-standalone,还没有弄懂两个的差别。

Chrome Version 49:官网最新

点击(此处)折叠或打开

  1. from selenium import webdriver

  2. driver = webdriver.Chrome()
  3. driver.get('');
脚本运行的时候出现了问题:在stack overflow上搜到了相同问题,链接

    
 "ChromeDriver executable needs to be available in the path. " selenium.common.exceptions.WebDriverException: Message: ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
   
最初认为chrome的安装路径没有在环境变量里面,因此把(反斜杠是解析空格)
 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome 
加到了环境变量里面,但是仍然不成功。因此参考stack上面给出的第一个答案,并不是特别理解,因此查看了。


 Follow these steps to setup your tests for running with ChromeDriver:

  • Ensure Chromium/Google Chrome is installed in a recognised location (确保浏览器安装在可识别的路径)
ChromeDriver expects you to have Chrome installed in the default location for your platform. You can also force ChromeDriver to use a custom location by setting a special capability.
  • Download the ChromeDriver binary for your platform under the  section of this site()
  • Help WebDriver find the downloaded ChromeDriver executable(让WebDriver能找到ChromeDriver有两种,1或者3)
Any of these steps should do the trick:
  1. include the ChromeDriver location in your PATH environment variable
  2. (Java only) specify its location via the webdriver.chrome.driver system property (see sample below)
  3. (Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)

点击(此处)折叠或打开

  1. import time
  2. from selenium import webdriver

  3. driver = webdriver.Chrome('/path/to/chromedriver') #Optional argument, if not specified will search path.
  4. driver.get('');
  5. time.sleep(5) # Let the user actually see
  6. search_box = driver.find_element_by_name('q')
  7. search_box.send_keys('ChromeDriver')
  8. search_box.submit()
  9. time.sleep(5) # Let the user actually see
  10. driver.quit()
1.ChromeDriver目录加入到环境变量
          vim ~/.bash_profile
          export PATH=$PATH:ChromeDriver目录(注意,是存放的目录,不是这个文件)
          :wq
          source ~/.bash_profile           

点击(此处)折叠或打开

  1. driver = webdriver.Chrome()
          成功

3.参考官网代码,把chrome driver目录作为参数path传给web driver

点击(此处)折叠或打开

  1. path = "/---/---path---/--/chromedriver"
  2. driver = webdriver.Chrome(path)
        此处一定要给出chromedriver的全目录,成功

阅读(13065) | 评论(0) | 转发(0) |
0

上一篇:堆排序--c实现(粗浅版)

下一篇:没有了

给主人留下些什么吧!~~