答案 0 :(得分:2)
设置set_page_load_timeout
,然后处理异常:
from __future__ import print_function
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
def get_page(driver, page):
try:
driver.get(page)
except TimeoutException:
pass
def main():
driver = webdriver.Chrome()
try:
driver.set_page_load_timeout(5)
get_page(driver, "http://your/long/url")
print("Returned from page get")
from pprint import pprint as pp
pp(driver.page_source)
finally:
driver.quit()
if __name__ == "__main__":
main()