简体   繁体   English

PhantomJS随机不退出(使用Selenium和Python)

[英]PhantomJS randomly does not exit (using Selenium with Python)

I'm using selenium-python with PhantomJS. 我正在使用Selenium-python和PhantomJS。 The code is pretty much like this: 代码非常像这样:

from selenium.webdriver import PhantomJS
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
driver = PhantomJS()
wait = WebDriverWait(driver, 10)
driver.get(url)
while True:
    // scrap the page
    try:
        driver.find_elements_by_css_selector('.next')[0].click()
    except: break
    wait.until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, '.loading')))
    wait.until(expected_conditions.invisibility_of_element_located((By.CSS_SELECTOR, '.loading')))
driver.quit()

I use a celery task which runs this code periodically. 我使用芹菜任务定期运行此代码。 The problem is that from time to time there are some stale phantomjs processes. 问题在于,有时会出现一些过时的幻影过程。 When I look into celery logs the task is completed successfully without any errors but the phantomjs process is still running. 当我查看芹菜日志时,任务成功完成,没有任何错误,但phantomjs进程仍在运行。

Some extra info: 一些额外的信息:

  • I'm using Python 3.2 我正在使用Python 3.2
  • I'm using Celery 3.1 with beat 我正在使用Celery 3.1
  • I'm using Debian Wheezy 我正在使用Debian Wheezy
  • I compiled PhamtomJS from source and created a symbolic link like this: ln -s /opt/phantomjs/bin/phantomjs /usr/local/bin/ 我从源代码编译了PhamtomJS并创建了一个符号链接: ln -s /opt/phantomjs/bin/phantomjs /usr/local/bin/

Can someone suggest a way to debug and find out who's fault is this? 有人可以建议一种方法来调试并找出这是谁的错吗?

I have not use celery before, are you sure celery will display all error message for you? 我之前没有使用芹菜,你确定芹菜会为你显示所有错误信息吗? For your code, I think if an exception occurs when running wait.until(...) , driver.quit() will not be executed. 对于您的代码,我认为如果在运行wait.until(...)时发生异常,则不会执行driver.quit()

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

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