selenium自动化操作浏览器(火狐)

from selenium import webdriver
import time

# import selenium
# print(help(selenium))

# selenium    三方库,可以实现让浏览器完成自动化的操作
# http://chromedriver.storage.googleapis.com/index.html
# http://npm.taobao.org/mirrors/chromedriver/
# 安装三大浏览器驱动driver
#      1.chromedriver 下载地址:https://code.google.com/p/chromedriver/downloads/list
#      2.Firefox的驱动geckodriver 下载地址:https://github.com/mozilla/geckodriver/releases/
#      3.IE的驱动IEdriver 下载地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/

#浏览器自动搜索 :1.创建浏览器对象(web_obj),选择浏览器驱动
                #2.设置要请求的url,发送请求   web_obj.get(url)
                #3.例如:用百度查询python资料    先通过方法找到输入框input,赋给一个变量,然后 变量.text('python') 发送关键字,
                #  接着找到搜索按钮,赋给一个变量, 变量.click()  点击 ; 最后 web_obj.quit() 关闭浏览器

#创建浏览器对象,  驱动为浏览器的驱动 .exe 文件
# 老师演示的是用谷歌浏览器,括号里传参时exe文件路径就是第一个参数,位置参数
#     我用的是火狐,要使用关键字参数
web_obj = webdriver.Firefox(executable_path=r'D:codepachong808geckodriver.exe')
print(web_obj)
# 设置url,发送请求
url = 'https://www.baidu.com'
web_obj.get(url)

#找到百度的输入框input
text = web_obj.find_element_by_id('kw')
#发送关键字
text.send_keys('陈钰琪')
#找到搜索按钮
button = web_obj.find_element_by_id('su')
#点击
button.click()
time.sleep(5)

#截屏
web_obj.save_screenshot('cyq1.png')


#关闭浏览器
web_obj.quit()

  

Firefox浏览器 版本驱动

下载地址:
原文地址:https://www.cnblogs.com/wshr210/p/11322909.html