Python selenium chrome 环境配置

简介: Python selenium chrome 环境配置 一、参考文章: 1. 记录一下python easy_install和pip安装地址和方法 http://heipark.
                         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 <module>
        #       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()

 

目录
相关文章
|
12天前
|
机器学习/深度学习 数据采集 TensorFlow
使用Python实现深度学习模型:智能垃圾分类与环境保护
使用Python实现深度学习模型:智能垃圾分类与环境保护 【8月更文挑战第7天】
28 2
|
7天前
|
Web App开发 数据可视化 Python
Python Selenium获取boss直聘招聘信息
Python Selenium获取boss直聘招聘信息
23 5
Python Selenium获取boss直聘招聘信息
|
6天前
|
数据采集 Python
如何用Python Selenium和WebDriver抓取LinkedIn数据并保存登录状态
本文介绍了使用Python Selenium和WebDriver库抓取LinkedIn数据的方法。首先,安装Selenium库和对应的WebDriver,然后配置爬虫代理IP以避免频繁请求被检测。接下来,设置user-agent和cookies以模拟真实用户行为,实现登录并保持状态。登录后,使用WebDriver抓取目标页面数据,如用户名、年龄、性别和简历信息。最后,强调了优化代码、处理异常和遵守使用条款的重要性,以提高效率并避免账号被封禁。
如何用Python Selenium和WebDriver抓取LinkedIn数据并保存登录状态
|
2天前
|
机器学习/深度学习 Ubuntu 数据挖掘
Ubuntu系统部署Anaconda环境及Python语言的详细流程
以上就是在Ubuntu系统中安装Anaconda环境及Python语言的详细流程。Anaconda为Python科学计算提供了便捷的管理方式,帮助用户轻松处理不同项目之间依赖管理的复杂性。通过以上步骤,你现在应该有了一个完全可用的Anaconda环境,可以开始在Ubuntu上进行Python编程和数据科学项目的探索了。
13 5
|
4天前
|
Web App开发 数据采集 测试技术
五分钟轻松掌握 Python 自动化测试 Selenium
本文主要介绍了 Selenium 相关内容,主要涉及 Selenium 知识面,从开始的 Python 小案例,到后面的 API 全面了解,以及 Selenium 的常用功能,到最后的 XPATH 以及爬虫的认知。这些内容已经能够全面,且具有实践性。
|
6天前
|
IDE Linux 开发工具
如何安装Python环境?
【8月更文挑战第13天】如何安装Python环境?
17 3
|
7天前
|
机器学习/深度学习 数据采集 TensorFlow
使用Python实现深度学习模型:智能环境监测与预警
【8月更文挑战第11天】 使用Python实现深度学习模型:智能环境监测与预警
26 2
|
14天前
|
Ubuntu Linux iOS开发
如何实现多个Python环境的Python版本切换
【8月更文挑战第4天】如何实现多个Python环境的Python版本切换
55 5
|
16天前
|
Linux 开发工具 Python
【Deepin 20系统】Linux系统从零打造完美VScode for Python环境
如何在Deepin 20系统中从零开始配置一个完美的VScode for Python开发环境,包括安装Anaconda、VScode、必要的插件、汉化、主题和字体设置,以及如何运行和调试Python程序。
28 5
|
19天前
|
测试技术 数据安全/隐私保护 Python
大麦网抢票攻略:使用Python Selenium实现
大麦网抢票攻略:使用Python Selenium实现