python爬虫--selenium等待页面加载

python爬虫,使用selenium
等待页面加载完成后,获取页面信息
指定等待时长内没有加载完成,抛出异常
 
  
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait

browser = webdriver.PhantomJS()
url = "http://xxx.html"
try:
 
  
    browser.get(url)
print time.time() WebDriverWait(browser, 10).until( lambda x: x.find_element_by_id( "room")) html = browser.page_source
 
  
    print html
except TimeoutException:
    print "timeout"

你可能感兴趣的:(爬虫)