[英]Selenium with Python keeps to load a page
我正在尝试使用简单的Python / Selenium脚本阅读页面
# encoding=utf8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import datetime as dt
import codecs
import os
myDriver=webdriver.Chrome()
myDriver.get("http://spb.beeline.ru/customers/products/mobile/tariffs/")
print "Test"
myDriver.quit()
现在,如果我使用谷歌浏览器打开该网址,则页面加载就完成了。 通过此脚本执行操作时,页面仍处于加载状态,并且脚本无法继续进行。
我在Windows 7上,使用Python 2.7.12,Selenium 2.53.6和chromedriver 2.24.41.74.31
我不确定该页面在做什么,但是肯定不是典型的。 我最好的建议是设置页面加载超时,然后处理关联的TimeoutException:
# encoding=utf8
from __future__ import print_function
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
myDriver=webdriver.Chrome()
try:
# Set the page load timeout
myDriver.set_page_load_timeout(10)
try:
myDriver.get("http://spb.beeline.ru/customers/products/mobile/tariffs/")
except TimeoutException:
print("Page expired")
# Do stuff here
finally:
myDriver.quit()
缺点是(我认为)这将杀死后台发生的任何阻止driver.get
调用返回的事件,因此某些页面功能可能会从根本上被破坏。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.