I use DryScrape to clean a javascript page, and sometimes it kills the process if it is an error. I tried using catch as per the documentation to prevent it, but I did not understand:
try: sess.visit('url')) except webkit_server.EndOfStreamError: continue except webkit_server.NoResponeerror: continue except webkit_server.InvalidResponseError: continue except webkit_server.NoX11Error: continue
So, I have such a setting to restart threads if they fail: class Checker (): def check_if_thread_is_alive (self): a = ThreadClass () a.start ()
b = ThreadClass() b.start() c = ThreadClass() c.start() d = ThreadClass() d.start() while True: if not a.is_alive(): print "Restarting A" a = ThreadClass() a.start() if not b.is_alive(): print "Restarting B" b = ThreadClass() b.start() if not c.is_alive(): print "Restarting C" c = ThreadClass() c.start() if not d.is_alive(): print "Restarting D" d = ThreadClass() d.start()
However, I get an error when I try to restart the stream:
Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "Scrapper.py", line 30, in run sess = dryscrape.Session(base_url = 'url') File "/usr/local/lib/python2.7/dist-packages/dryscrape/session.py", line 18, in __init__ self.driver = driver or DefaultDriver() File "/usr/local/lib/python2.7/dist-packages/dryscrape/driver/webkit.py", line 30, in __init__ super(Driver, self).__init__(**kw) File "/usr/local/lib/python2.7/dist-packages/webkit_server.py", line 225, in __init__ self.conn = connection or ServerConnection() File "/usr/local/lib/python2.7/dist-packages/webkit_server.py", line 444, in __init__ self._sock = (server or get_default_server()).connect() File "/usr/local/lib/python2.7/dist-packages/webkit_server.py", line 414, in connect sock.connect(("127.0.0.1", self._port)) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) error: [Errno 111] Connection refused
Is there a better way to solve this problem or is something missing?
user2540748
source share