简体   繁体   中英

Python+Selenium+PhantomJS. Waiting for proxy

The code is given proxy to using it through the PhantomJS to load the page. But it happens that proxies are either too slow or does not work. Tell me please how to make sure that the page is trying to open, but for example on the expiration of 20-30 seconds was issued a message that "The proxy does not work.

from selenium import webdriver
browser=webdriver.PhantomJS()
service_args = [
    '--proxy=10.10.20.20:3128',
    '--proxy-type=http',
    ]
browser = webdriver.PhantomJS(service_args=service_args)
browser.get('http://check-host.net/ip')
browser.quit()

Maybe "Try....Catch..." Help me plese. Thank you advance!

try: <browser.get()> sleep(5) except Exception as e: print e

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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