forked from scrapy-plugins/scrapy-playwright
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexception_errback.py
30 lines (24 loc) · 969 Bytes
/
exception_errback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging
from scrapy import Spider, Request
class HandleExceptionInErrbackSpider(Spider):
"""Handle exceptions in the Playwright downloader, such as TimeoutError"""
name = "awesome"
custom_settings = {
"PLAYWRIGHT_DEFAULT_NAVIGATION_TIMEOUT": 1000, # milliseconds
"TWISTED_REACTOR": "twisted.internet.asyncioreactor.AsyncioSelectorReactor",
"DOWNLOAD_HANDLERS": {
"https": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
# "http": "scrapy_playwright.handler.ScrapyPlaywrightDownloadHandler",
},
"RETRY_TIMES": 0,
}
def start_requests(self):
yield Request(
url="https://httpbin.org/delay/10",
meta={"playwright": True},
errback=self.errback,
)
def errback(self, failure):
logging.info(
"Handling failure in errback, request=%r, exception=%r", failure.request, failure.value
)