标签:exe strong bsp pre seconds loading tps home exception
例如:get 汽车之家页面时会等待很长时间,其实页面基本元素都已加载,可进行后续操作
可以通过set_page_load_time()方法来设定时间,
然后捕获timeout异常 并 通过执行Javascript来停止页面加载 window.stop()
1 from selenium.common.exceptions import TimeoutException 2 3 startTime = time.time() 4 print "start time is: %0.3f"%startTime 5 driver = webdriver.Firefox() 6 # 设定页面加载限制时间 7 driver.set_page_load_timeout(30) 8 driver.maximize_window() 9 10 try: 11 driver.get(‘http://www.autohome.com.cn/‘) 12 except TimeoutException: 13 print ‘time out after 30 seconds when loading page‘ 14 driver.execute_script(‘window.stop()‘) #当页面加载时间超过设定时间,通过执行Javascript来stop加载,即可执行后续动作
1 from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 2 myFF = FirefoxBinary(‘/root/bobo/firefox/firefox-bin‘) 3 driver = webdriver.Firefox(firefox_binary=myFF)
[转载]Python & Selenium -- 页面加载时间过长&启动指定FF
标签:exe strong bsp pre seconds loading tps home exception
原文地址:http://www.cnblogs.com/chromecs/p/6224498.html