Setting timeout on selenium webdriver.PhantomJS

后端 未结 2 606
醉酒成梦
醉酒成梦 2020-12-28 09:49

The situation

I have a simple python script to get the HTML source for a given url:

    browser = webdriver.PhantomJS()
            


        
2条回答
  •  伪装坚强ぢ
    2020-12-28 10:52

    PhantomJS has provided resourceTimeout, which might suit your needs. I quote from documentation here

    (in milli-secs) defines the timeout after which any resource requested will stop trying and proceed with other parts of the page. onResourceTimeout callback will be called on timeout.

    So in Ruby, you can do something like

    require 'selenium-webdriver'
    
    capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs("phantomjs.page.settings.resourceTimeout" => "5000")
    driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities
    

    I believe in Python, it's something like (untested, only provides the logic, you are the Python developer, hopefully you will figure out)

    driver = webdriver.PhantomJS(desired_capabilities={'phantomjs.page.settings.resourceTimeout': '5000'})
    

提交回复
热议问题