下面文档的脚本执行,必须要下载 谷歌浏览器对应的驱动详细的流程时
selenium的使用流程 a 环境的安装 b 谷歌浏览器驱动下载地址:http://chromedriver.storage.googleapis.com/index.html c 驱动程序和浏览器之间的映射关系对应的地址: http://blog.csdn.net/huilan_same/article/details/51896672 -- d 实例化一个浏览器对象: e 编写基于浏览器自动化的相关操作代码了
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
#from selenium.webdriver.common.keys import Keys
import time
#from selenium.webdriver import ActionChains
# 导入驱动程序
s = Service("chromedriver.exe")
driver = webdriver.Chrome(service=s)
# 选择url
url = "https://qzone.qq.com/"
driver.get(url=url)
# iframe 标签定位
driver.switch_to.frame("login_frame")
time.sleep(3)
# //*[@id="switcher_plogin"]
driver.find_element(By.XPATH, "//*[@id='switcher_plogin']").click()
time.sleep(4)
# 页面框填入 账号密码
driver.find_element(By.ID, "u").send_keys("qq")
time.sleep(2)
driver.find_element(By.ID, "p").send_keys("qq密码")
time.sleep(2)
# 点击登录
driver.find_element(By.ID, "login_button").click()
time.sleep(50)
driver.quit()