jQuery火箭图标返回顶部代码

如果没有安装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()

原文地址:https://www.cnblogs.com/v5captain/p/13167413.html