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