I'm using selenium-python with 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.
Some extra info:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With