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()

 

目录
相关文章
|
2月前
|
数据采集 Web App开发 JavaScript
基于Selenium的Python爬虫抓取动态App图片
基于Selenium的Python爬虫抓取动态App图片
251 68
|
2月前
|
人工智能 安全 Shell
Jupyter MCP服务器部署实战:AI模型与Python环境无缝集成教程
Jupyter MCP服务器基于模型上下文协议(MCP),实现大型语言模型与Jupyter环境的无缝集成。它通过标准化接口,让AI模型安全访问和操作Jupyter核心组件,如内核、文件系统和终端。本文深入解析其技术架构、功能特性及部署方法。MCP服务器解决了传统AI模型缺乏实时上下文感知的问题,支持代码执行、变量状态获取、文件管理等功能,提升编程效率。同时,严格的权限控制确保了安全性。作为智能化交互工具,Jupyter MCP为动态计算环境与AI模型之间搭建了高效桥梁。
183 2
Jupyter MCP服务器部署实战:AI模型与Python环境无缝集成教程
|
2月前
|
Python
在VScode环境下配置Python环境的方法
经过上述步骤,你的VSCode环境就已经配置好了。请尽情享受这扇你为自己开启的知识之窗。如同你在冒险世界中前行,你的探索之路只有越走越广,你获得的知识只会越来越丰富,你的能力只会越来越强。
205 37
|
2月前
|
数据采集 Web App开发 前端开发
Python+Selenium爬虫:豆瓣登录反反爬策略解析
Python+Selenium爬虫:豆瓣登录反反爬策略解析
|
4月前
|
Web App开发 数据采集 前端开发
Python + Chrome 爬虫:如何抓取 AJAX 动态加载数据?
Python + Chrome 爬虫:如何抓取 AJAX 动态加载数据?
|
5月前
|
数据采集 Web App开发 存储
打造高效的Web Scraper:Python与Selenium的完美结合
本文介绍如何使用Python结合Selenium,通过代理IP、设置Cookie和User-Agent抓取BOSS直聘的招聘信息,包括公司名称、岗位、要求和薪资。这些数据可用于行业趋势、人才需求、企业动态及区域经济分析,为求职者、企业和分析师提供宝贵信息。文中详细说明了环境准备、代理配置、登录操作及数据抓取步骤,并提醒注意反爬虫机制和验证码处理等问题。
130 1
打造高效的Web Scraper:Python与Selenium的完美结合
|
4月前
|
Java API Docker
在线编程实现!如何在Java后端通过DockerClient操作Docker生成python环境
以上内容是一个简单的实现在Java后端中通过DockerClient操作Docker生成python环境并执行代码,最后销毁的案例全过程,也是实现一个简单的在线编程后端API的完整流程,你可以在此基础上添加额外的辅助功能,比如上传文件、编辑文件、查阅文件、自定义安装等功能。 只有锻炼思维才能可持续地解决问题,只有思维才是真正值得学习和分享的核心要素。如果这篇博客能给您带来一点帮助,麻烦您点个赞支持一下,还可以收藏起来以备不时之需,有疑问和错误欢迎在评论区指出~
在线编程实现!如何在Java后端通过DockerClient操作Docker生成python环境
|
6月前
|
Shell Linux Ruby
Python3虚拟环境venv
`venv` 是 Python 的虚拟环境工具,用于为不同项目创建独立的运行环境,避免依赖冲突。通过 `python3 -m venv` 命令创建虚拟环境,并使用 `source bin/activate` 激活。激活后,所有 Python 包将安装在该环境中,不影响系统全局环境。退出环境使用 `deactivate` 命令。每个虚拟环境拥有独立的包集合,确保项目间的隔离性。删除虚拟环境只需删除其目录即可。
221 34
|
5月前
|
Web App开发 数据采集 数据安全/隐私保护
Selenium库详解:Python实现模拟登录与反爬限制的进阶指南
Selenium库详解:Python实现模拟登录与反爬限制的进阶指南
|
6月前
|
SQL 分布式计算 数据处理
云产品评测|分布式Python计算服务MaxFrame | 在本地环境中使用MaxFrame + 基于MaxFrame实现大语言模型数据处理
本文基于官方文档,介绍了由浅入深的两个部分实操测试,包括在本地环境中使用MaxFrame & 基于MaxFrame实现大语言模型数据处理,对步骤有详细说明。体验下来对MaxCompute的感受是很不错的,值得尝试并使用!
146 1

推荐镜像

更多