1.环境
python2.7+selenium+phantomjs+linux
2.代码
#-*-coding:utf-8 -*- from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = webdriver.PhantomJS() driver.maximize_window() #窗口最大化 driver.get('http://www.baidu.com') driver.save_screenshot('1.png') #保存图片 element = driver.find_element_by_id('kw') element.send_keys('sina') #输入搜索内容 element.send_keys(Keys.RETURN) #模拟回车 time.sleep(1) #延时长短跟页面加载时间有关 driver.save_screenshot('2.png') driver.quit()