Scrapy/BigQuery在关闭spider时失败,并发送以下错误:OSError:[Errno 5]Input/Outpu

2024-05-29 02:29:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我启动了一个爬行蜘蛛,从网上购物网页上抓取一个类别。大约有76万件物品。11个小时后,我看了看圆木,我意识到蜘蛛不知怎么关上了。调用管道中的close_spider()函数时失败。基本上,我自己实现的close_spider()函数在spider和bigquery之间建立连接,并将本地保存的jsonlines文件传输到bigquery数据库。然而,正如我提到的,它在这一步中失败了。在

我手动尝试了close_spider()函数,它成功地将保存的jsonlines文件传输到bigquery。顺便说一下,jsonlines文件中大约有466k行。另外,我在一个有8k个条目的不同类别上尝试了相同的spider,它成功地将feed文件传输到bigquery,没有收到错误消息。我遇到这个错误两次。当我第一次收到这个错误消息时,蜘蛛刮走了700k个项目。在

以下是日志文件:

2019-06-11 23:18:12 [scrapy.extensions.logstats] INFO: Crawled 480107 pages (at 787 pages/min), scraped 466560 items (at 772 items/min)
2019-06-11 23:18:33 [scrapy.core.engine] INFO: Closing spider (finished)
2019-06-11 23:18:33 [scrapy.core.engine] ERROR: Scraper close failure
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 654, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "/home/togayyazar/etsy/etsy/pipelines.py", line 20, in close_spider
    self.write_to_bq()
  File "/home/togayyazar/etsy/etsy/pipelines.py", line 30, in write_to_bq
    print("-----BIGQUERY-----")
OSError: [Errno 5] Input/output error
2019-06-11 23:18:33 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 217195256,
 'downloader/request_count': 480652,
 'downloader/request_method_count/GET': 480652,
 'downloader/response_bytes': 29983627714,
 'downloader/response_count': 480652,
 'downloader/response_status_count/200': 480373,
 'downloader/response_status_count/301': 254,
 'downloader/response_status_count/400': 6,
 'downloader/response_status_count/503': 19,
 'dupefilter/filtered': 358230,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2019, 6, 11, 23, 18, 33, 739888),
 'httperror/response_ignored_count': 6,
 'httperror/response_ignored_status_count/400': 6,
 'item_scraped_count': 466833,
 'log_count/ERROR': 1,
 'log_count/INFO': 663,
 'memusage/max': 456044544,
 'memusage/startup': 61976576,
 'request_depth_max': 88,
 'response_received_count': 480379,
 'retry/count': 19,
 'retry/reason_count/503 Service Unavailable': 19,
 'scheduler/dequeued': 480652,
 'scheduler/dequeued/memory': 480652,
 'scheduler/enqueued': 480652,
 'scheduler/enqueued/memory': 480652,
 'start_time': datetime.datetime(2019, 6, 11, 12, 30, 12, 400853)}
2019-06-11 23:18:33 [scrapy.core.engine] INFO: Spider closed (finished)

和close_spider()函数:

^{pr2}$

任何帮助都将不胜感激。在


Tags: 函数infoclosedatetimeresponserequeststatuscount
1条回答
网友
1楼 · 发布于 2024-05-29 02:29:00

如果您查看错误跟踪,您将看到print()函数中出现异常。在

File "/home/togayyazar/etsy/etsy/pipelines.py", line 30, in write_to_bq
    print("  -BIGQUERY  -") OSError: [Errno 5] Input/output error

检查this thread以了解问题。在

我建议您只需删除print或将其替换为logging模块,如果您想使用,spider有一个属性logger,但是如果您希望有一个具有管道名称的记录器,可以这样做:

^{pr2}$

相关问题 更多 >

    热门问题