美文网首页菜鸟的Python之路
Python+selenium环境搭建

Python+selenium环境搭建

作者: Tester_Jingel | 来源:发表于2017-03-01 17:07 被阅读108次

    python+selenium.png

    一、下载安装Python

    下载并安装Python,此处博主使用的是Python3.5
    点击下载Python3.5安装包(Windows64位)

    二、配置环境变量

    • python安装完成后,打开cmd输入“Python”,若输出版本号已代表安装成功


      Python版本.png
    • 若提示Python不识别,则需要配置环境变量


      配置环境变量.png

    三、安装pip和setuptool工具

    • setuptools工具下载链接
      setuptools工具.png
      -复制这些下载下来的文件到Python目录下,打开cmd,进入对应的目录,输入python setup.py等,安装第三方工具

    四、安装selenium模块

    打开cmd,进入到Python的scripts目录下,输入pip install -U selenium


    安装selenium.png

    五、开始你的第一个simple demo

    打开Python IDE,ctrl+n新建文档,输入以下代码:

    # -*-coding:utf-8-*-
    #executable_path="F:\chengyuanyuanproject\python35\geckodriver.exe"
    from selenium import webdriver
    browser = webdriver.Chrome()
    browser.get("http://www.baidu.com")
    
    browser.find_element_by_id("kw").send_keys("selenim")
    browser.find_element_by_id("su").click()
    
    browser.quit()
    print ("百度测试成功O(∩_∩)O哈哈~")
    
    

    常见问题:

    • 导入模块失败,打不开浏览器报错需要将这个下载到Python路径下
      selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
      geckodriver驱动下载地址
    • 由于本人一直未能使用上面的驱动正常使用(ps:可能是和自己安装的Firefox的版本不一致,代理啥的也检查了没错,为了不浪费时间决定使用了chrome了O(∩_∩)O),所以下载了chromedriver
      chromedriver驱动下载地址

    推荐Python学习链接:

    今天有学习了一点,一天一步慢慢进步,哈哈向着目标前进,↖(ω)↗

    相关文章

      网友评论

        本文标题:Python+selenium环境搭建

        本文链接:https://www.haomeiwen.com/subject/kstcgttx.html