selenium chromedriver-在python split网络爬虫中设置一个timout



尝试在python中设置超时,就像在ruby中一样。

我有一个链接,当我点击它时,它会打开一个弹出窗口,但我无法访问它,因为它会导致脚本冻结,直到我杀死它。我已经尝试访问这个弹出窗口好几个月了,但在ruby watir网络驱动程序中没有任何乐趣。

我正在尝试暂停呼叫以弹出,然后访问弹出窗口。

@timeout(3)
try:
b.execute_script("javascript:openMdlWindow('InvestmentDetailOptions.aspx?IDAssetType=','620','600');if(window.document.RetValue == '2'){window.parent.LoadinIframe('InvestmentDetail.aspx?FromMenu=N&IDAssetType=','Investment Details > Full View','false');}")
except Exception, e:
print 'timeout!'

任何帮助都将不胜感激。

试试这个:

from splinter import Browser
from selenium.common.exceptions import TimeoutException
b = Browser('firefox')
b.driver.set_page_load_timeout(1)
try:
   b.visit('http://www.bbc.com')
except TimeoutException:
   pass
print b.html
import signal
from time import sleep
class TimeoutException(Exception):
    pass
def do_something_else():
    time = 5
    sleep(time)
    return 'do_something_else has to run for %d seconds' % time
def handler(signum, frame):
    raise TimeoutException 
def do_something_with_timeout(callback, timeout=3):
    signal.signal(signal.SIGALRM, handler)
    signal.alarm(timeout)
    try:
        value = callback()
        signal.alarm(0)
        return value
    except TimeoutException:
        pass
    signal.signal(signal.SIGALRM, signal.SIG_IGN)
    return 'time out'
def main():
    print 'hello'
    print do_something_with_timeout(do_something_else)
    print 'world'
main()

相关内容

  • 没有找到相关文章

最新更新