gpt4 book ai didi

python - 尝试重新启动 webscraper 线程时连接被拒绝

转载 作者:太空狗 更新时间:2023-10-30 00:02:44 27 4
gpt4 key购买 nike

我正在使用 DryScrape 抓取一个 javascript 页面,如果出现错误,它偶尔会终止进程。我已经尝试根据文档使用 catch 来防止它,但我还没有弄明白:

        try:
sess.visit('url'))
except webkit_server.EndOfStreamError:
continue
except webkit_server.NoResponeerror:
continue
except webkit_server.InvalidResponseError:
continue
except webkit_server.NoX11Error:
continue

所以我有这样的设置来在线程崩溃时重新启动线程:类检查器(): def check_if_thread_is_alive( self ): a = 线程类() a.开始()

    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()

但是,每当我尝试重新启动线程时,我最终都会收到错误消息:

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

是否有更好的方法来尝试解决这个问题,或者我缺少什么?

最佳答案

因为:您正在尝试连接到自己。

need change target url.

如果想连接到你自己,先创建服务。

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 <<<--- you're trying to connect to yourself.
return getattr(self._sock,name)(*args)

关于python - 尝试重新启动 webscraper 线程时连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26960522/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com