1 from selenium import webdriver 2 import time 3 4 def controlBrowser(): 5 #启动浏览器 6 driver = webdriver.Firefox() 7 #打开网站 8 driver.get('http://www.baidu.com') 9 #设置浏览器大小10 driver.set_window_size(800,600)11 #刷新页面12 driver.find_element_by_id('kw').send_keys('python')13 driver.refresh()14 # 输入关键字15 driver.find_element_by_id('kw').send_keys('python')16 #点击搜索17 driver.find_element_by_id('su').click()18 #后退至百度首页19 driver.back()20 time.sleep(3)21 #前进至搜索页22 driver.forward()