GeckoDriver+Selenium+Python的安装和使用


如果没有安装GeckoDriver会提示:

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

一、下载GeckoDriver

下载地址:https://github.com/mozilla/geckodriver/releases

我的是windows 10选择的是geckodriver-v0.26.0-win64.zip

二、解压后放入C:\Python27(我之前已经把Python根目录设置为环境变量)

新打开一个cmd窗口,有如下提示则为成功:geckodriver -h

三、 安装selenium:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple selenium

四、打开百度并搜索船长博客:

#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver
import time

browser = webdriver.Firefox()
browser.get("http://www.baidu.com")
browser.find_element_by_id("kw").send_keys(u"船长博客")
browser.find_element_by_id("su").click()
time.sleep(5)
browser.quit()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM