简体   繁体   English

Selenium与Python不断加载页面

[英]Selenium with Python keeps to load a page

I am trying to read a page using a simple Python/Selenium script 我正在尝试使用简单的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()

Now, if i open that url using google chrome, the page load and that's it. 现在,如果我使用谷歌浏览器打开该网址,则页面加载就完成了。 While doing it through this script, the page remains in a load state and the script can't go further. 通过此脚本执行操作时,页面仍处于加载状态,并且脚本无法继续进行。

I'm on Windows 7, using Python 2.7.12, Selenium 2.53.6 and chromedriver 2.24.41.74.31 我在Windows 7上,使用Python 2.7.12,Selenium 2.53.6和chromedriver 2.24.41.74.31

I'm not sure what that page is doing, but it is certainly atypical. 我不确定该页面在做什么,但是肯定不是典型的。 My best suggestion is to set the page load timeout and then handle the associated TimeoutException: 我最好的建议是设置页面加载超时,然后处理关联的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()

The downside is that (I think) this will kill whatever is happening in the back ground that prevents the driver.get call from returning, so some page functionality may be fundamentally broken. 缺点是(我认为)这将杀死后台发生的任何阻止driver.get调用返回的事件,因此某些页面功能可能会从根本上被破坏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM