2013-07-04 19 views
6

Tôi đã thiết kế trình thu thập thông tin nơi sẽ có hai trình thu thập thông tin. Tôi đã thiết kế các lỗi này bằng cách sử dụng các mẩu tin lưu niệm.
Những trình thu thập thông tin này sẽ chạy độc lập bằng cách tìm nạp dữ liệu từ cơ sở dữ liệu.lỗi cổng trong phế liệu

Chúng tôi đang chạy các trình thu thập này bằng cách sử dụng lò phản ứng. Chúng tôi biết rằng chúng tôi không thể chạy lò phản ứng liên tục
chúng tôi cung cấp khoảng 500 liên kết tới nhện thứ hai để thu thập thông tin. Nếu chúng tôi làm như vậy, chúng tôi gặp trục trặc về cổng. nghĩa là phế liệu chỉ sử dụng một cổng

Error caught on signal handler: <bound method ?.start_listening of <scrapy.telnet.TelnetConsole instance at 0x0467B440>> 
Traceback (most recent call last): 
File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 1070, in _inlineCallbacks 
result = g.send(result) 
File "C:\Python27\lib\site-packages\scrapy-0.16.5-py2.7.egg\scrapy\core\engine.py", line 75, in start yield self.signals.send_catch_log_deferred(signal=signals.engine_started) 
File "C:\Python27\lib\site-packages\scrapy-0.16.5-py2.7.egg\scrapy\signalmanager.py", line 23, in send_catch_log_deferred 
return signal.send_catch_log_deferred(*a, **kw) 
File "C:\Python27\lib\site-packages\scrapy-0.16.5-py2.7.egg\scrapy\utils\signal.py", line 53, in send_catch_log_deferred 
*arguments, **named) 
--- <exception caught here> --- 
File "C:\Python27\lib\site-packages\twisted\internet\defer.py", line 137, in maybeDeferred 
result = f(*args, **kw) 
File "C:\Python27\lib\site-packages\scrapy-0.16.5-py2.7.egg\scrapy\xlib\pydispatch\robustapply.py", line 47, in robustApply 
return receiver(*arguments, **named) 
File "C:\Python27\lib\site-packages\scrapy-0.16.5-py2.7.egg\scrapy\telnet.py", line 47, in start_listening 
self.port = listen_tcp(self.portrange, self.host, self) 
File "C:\Python27\lib\site-packages\scrapy-0.16.5-py2.7.egg\scrapy\utils\reactor.py", line 14, in listen_tcp 
return reactor.listenTCP(x, factory, interface=host) 
File "C:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 489, in listenTCP 
p.startListening() 
File "C:\Python27\lib\site-packages\twisted\internet\tcp.py", line 980, in startListening 
raise CannotListenError(self.interface, self.port, le) 
twisted.internet.error.CannotListenError: Couldn't listen on 0.0.0.0:6073: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted. 

Vì vậy, sự cố xảy ra ở đây là gì ?? Sau đó, cách tối ưu để giải quyết tình huống này là gì? Vui lòng giúp đỡ ...

p.s: Tôi đã tăng số cổng trong cài đặt nhưng luôn lấy 6073 làm mặc định.

+0

Bạn có thể cho biết cách bạn chạy trình thu thập thông tin và cách bạn định cấu hình chúng? – alecxe

+1

đây có phải là bản sao của http://stackoverflow.com/questions/1767553/twisted-errors-in-scrapy-spider –

+0

@ Jean-PaulCalderone Không giống nhau, tôi đã vô hiệu hóa các trang web và bảng điều khiển telnet nhưng hiển thị lỗi giống nhau của nó. – sathish

Trả lời

5

Cách dễ nhất sẽ được vô hiệu hóa Console Telnet bằng cách thêm này để settings.py của bạn:

EXTENSIONS = { 
    'scrapy.telnet.TelnetConsole': None 
} 

Xem thêm http://doc.scrapy.org/en/latest/topics/settings.html#extensions cho một danh sách các phần mở rộng theo mặc định được kích hoạt.

+1

Nó hiển thị cùng một bộ lỗi ngay cả sau khi thêm Tiện ích vào cài đặt. – sathish

1

Sự cố của bạn có thể được giải quyết bằng cách chạy ít trình thu thập dữ liệu đồng thời hơn. Đây là một công thức tôi đã viết để thực hiện các yêu cầu tuần tự: Lớp cụ thể này chỉ chạy một trình thu thập thông tin, nhưng các sửa đổi cần thiết để làm cho các lô chạy (nói 10 tại một thời điểm) là tầm thường.

class SequentialCrawlManager(object): 
    """Start spiders sequentially""" 

    def __init__(self, spider, websites): 
     self.spider = spider 
     self.websites = websites 
     # setup crawler 
     self.settings = get_project_settings() 
     self.current_site_idx = 0 

    def next_site(self): 
     if self.current_site_idx < len(self.websites): 
      self.crawler = Crawler(self.settings) 
      # the CSVs data in each column is passed as keyword arguments 
      # the arguments come from the 
      spider = self.spider() # pass arguments if desired 
      self.crawler.crawl(spider) 
      self.crawler.start() 
      # wait for one spider to finish before starting the next one 
      self.crawler.signals.connect(self.next_site, signal=signals.spider_closed) 
      self.crawler.configure() 
      self.current_site_idx += 1 
     else: 
      reactor.stop() # required for the program to terminate 

    def start(self): 
     log.start() 
     self.next_site() 
     reactor.run() # blocking call