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

2024-04-19 14:25:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在将selenium-python与PhantomJS一起使用。代码大致如下:

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()

我使用一个定期运行此代码的celery任务。问题是,有时会有一些过时的phantomjs进程。当我查看celery日志时,任务成功完成,没有任何错误,但phantomjs进程仍在运行。在

一些额外的信息:

  • 我使用的是python3.2
  • 我用芹菜3.1和节拍
  • 我用的是德比安喘乐
  • 我从源代码编译了PhamtomJS并创建了一个如下的符号链接:ln -s /opt/phantomjs/bin/phantomjs /usr/local/bin/

有人能提出一种调试方法,找出谁的错吗?在


Tags: 代码fromimportsupportbydriverseleniumphantomjs
1条回答
网友
1楼 · 发布于 2024-04-19 14:25:44

我以前没有用过芹菜,你确定芹菜会为你显示所有的错误信息吗?对于您的代码,我认为如果在运行wait.until(...)时发生异常,driver.quit()将不会执行。在

相关问题 更多 >