From 90e997a500f7acc36114dacf6414d82cb6a96728 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Mon, 1 May 2017 23:50:13 +0200 Subject: [PATCH] Use xvfbwrapper for Firefox --- handler.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/handler.py b/handler.py index 27815fa..c0dcf9d 100755 --- a/handler.py +++ b/handler.py @@ -4,6 +4,7 @@ from bs4 import BeautifulSoup from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import NoSuchElementException +from xvfbwrapper import Xvfb import multiprocessing, urllib.request, urllib.error, urllib.parse, time, os import dbtools, phototools, setuptools @@ -126,20 +127,13 @@ def siteHandler(driver, mode = 0, p = 0, db = dbtools.dbHelper()): if pageHandler(driver, db): siteHandler(driver, mode, p+1, db) -def mainHandler(): +def mainHandler(driver, db): siteHandler(driver, 0, db=db) siteHandler(driver, 1, db=db) if __name__ == "__main__": - db = dbtools.dbHelper() - driver = webdriver.Firefox() - try: - if loginHandler(driver): - p = multiprocessing.Process(target=mainHandler) - p.start() - p.join(1500) - if p.is_alive(): - p.terminate() - p.join() - finally: + with Xvfb() as xvfb: + db = dbtools.dbHelper() + driver = webdriver.Firefox() + mainHandler(driver, db) driver.close()