selenium框架的使用

selenium是浏览器自动化测试框架,使用前可直接pip install selenium安装

需要选择与当前使用浏览器匹配的驱动下载调用。本次采用Chrome 74版,Chrome驱动下载地址:http://chromedriver.storage.googleapis.com/index.html

使用小案例:

from selenium import webdriver
from time import sleep

bower=webdriver.Chrome(executable_path=r'C:\Users\asaxh\Desktop\chromedriver.exe')

bower.get(url='https://www.hao123.com/')        #指定导航栏URL
sleep(2)

text_input=bower.find_element_by_name('word')
text_input.send_keys('胡歌')                     #要搜素的内容
sleep(2)

bower.find_element_by_class_name('submitInput').click() #点击搜素
sleep(3)

bower.quit()        #关闭浏览器并退出

猜你喜欢

转载自www.cnblogs.com/wen-kang/p/10954647.html