我運行在遠程的webdriver模式phantomjs與phantomjs --webdriver 8910
,然後讓使用硒python綁定多頁的東西,如:使用selenium webdriver限制phantomjs的內存使用情況?
wd = webdriver.PhantomJS(port=8910)
for url in big_url_list:
wd.get(url)
# do something here, e.g. wd.save_screenshot or print wd.page_source
wd.quit()
的wd.quit()
顯得無能爲力。用top監視進程表明,隨着更多頁面的檢索,phantomjs進程的內存使用量不斷增加。如果我重新啓動phantomjs進程,那麼內存使用量會降低,並開始穩定爬升。
close method mentioned in the phantomjs docs聽起來很有希望,但我看不到通過WebDriver protocol調用該方法的任何方法。
有沒有(i)一種方法可以在進行多次請求時保持幻像的內存使用量,或者(ii)監控和定期重啓phantomjs進程的可靠方法,使內存永不失控?