簡體   English   中英

Selenium與Python不斷加載頁面

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM