1.pip安装 selenium
2.下载浏览器驱动
火狐:geckodriver.exe https://pan.baidu.com/s/1GPXYBLNOW7PUbpPrCy0_YA
谷歌:https://npm.taobao.org/mirrors/chromedriver/
注:火狐是selenium默认的浏览器
3.下载好的驱动(geckodriver.exe )放于浏览器的安装目录下;
添加path到系统路径;
重启pytharm;
4.此外注意声明时路径
webdriver.Firefox(executable_path='c:/firefox安装目录/geckodriver.exe')
# coding:utf-8
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
# seleninm 默认火狐浏览器, 或 webdriver.Firefox(executable_path='c:/geckodriver.exe') ;添加到系统path路径;重启pytharm。
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
#鼠标悬停 1
driver.get("https://www.baidu.com")
time.sleep(2)
ActionChains(driver).move_to_