案例三:执行 JavaScript 语句
from selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("https://www.baidu.com/")
js = "var q=document.getElementById(\"kw\");q.style.border=\"2px solid red\";"
driver.execute_script(js)
driver.save_screenshot("redbaidu.png")
img = driver.find_element_by_xpath("//*[@id='lg']/img")
driver.execute_script('$(arguments[0]).fadeOut()',img)
driver.execute_script("$('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);});")
driver.save_screenshot("nullbaidu.png")
driver.quit()
from selenium import webdriver
import time
driver = webdriver.PhantomJS()
driver.get("https://movie.douban.com/typerank?type_name=剧情&type=11&interval_id=100:90&action=")
js = "document.body.scrollTop=10000"
time.sleep(3)
driver.save_screenshot("douban.png")
driver.execute_script(js)
time.sleep(10)
driver.save_screenshot("newdouban.png")
driver.quit()