Use xvfbwrapper for Firefox

This commit is contained in:
Klaus-Uwe Mitterer 2017-05-01 23:50:13 +02:00
parent 5a6a05cab9
commit 90e997a500

View file

@ -4,6 +4,7 @@ from bs4 import BeautifulSoup
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoSuchElementException
from xvfbwrapper import Xvfb
import multiprocessing, urllib.request, urllib.error, urllib.parse, time, os import multiprocessing, urllib.request, urllib.error, urllib.parse, time, os
import dbtools, phototools, setuptools import dbtools, phototools, setuptools
@ -126,20 +127,13 @@ def siteHandler(driver, mode = 0, p = 0, db = dbtools.dbHelper()):
if pageHandler(driver, db): if pageHandler(driver, db):
siteHandler(driver, mode, p+1, db) siteHandler(driver, mode, p+1, db)
def mainHandler(): def mainHandler(driver, db):
siteHandler(driver, 0, db=db) siteHandler(driver, 0, db=db)
siteHandler(driver, 1, db=db) siteHandler(driver, 1, db=db)
if __name__ == "__main__": if __name__ == "__main__":
db = dbtools.dbHelper() with Xvfb() as xvfb:
driver = webdriver.Firefox() db = dbtools.dbHelper()
try: driver = webdriver.Firefox()
if loginHandler(driver): mainHandler(driver, db)
p = multiprocessing.Process(target=mainHandler)
p.start()
p.join(1500)
if p.is_alive():
p.terminate()
p.join()
finally:
driver.close() driver.close()