简体   繁体   English

Python+Selenium+PhantomJS。 等待代理

[英]Python+Selenium+PhantomJS. Waiting for proxy

The code is given proxy to using it through the PhantomJS to load the page.代码被赋予代理以通过 PhantomJS 使用它来加载页面。 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.请告诉我如何确保页面正在尝试打开,但例如在 20-30 秒到期时发出一条消息“代理不起作用。

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

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

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