Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4803 from elacuesta/instantiate-resolution-receiver
CachingHostnameResolver
- Loading branch information
Showing
6 changed files
with
116 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import sys | ||
|
||
import scrapy | ||
from scrapy.crawler import CrawlerProcess | ||
|
||
|
||
class CachingHostnameResolverSpider(scrapy.Spider): | ||
""" | ||
Finishes in a finite amount of time (does not hang indefinitely in the DNS resolution) | ||
""" | ||
name = "caching_hostname_resolver_spider" | ||
|
||
def start_requests(self): | ||
yield scrapy.Request(self.url) | ||
|
||
def parse(self, response): | ||
for _ in range(10): | ||
yield scrapy.Request(response.url, dont_filter=True, callback=self.ignore_response) | ||
|
||
def ignore_response(self, response): | ||
self.logger.info(repr(response.ip_address)) | ||
|
||
|
||
if __name__ == "__main__": | ||
process = CrawlerProcess(settings={ | ||
"RETRY_ENABLED": False, | ||
"DNS_RESOLVER": "scrapy.resolver.CachingHostnameResolver", | ||
}) | ||
process.crawl(CachingHostnameResolverSpider, url=sys.argv[1]) | ||
process.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import scrapy | ||
from scrapy.crawler import CrawlerProcess | ||
|
||
|
||
class CachingHostnameResolverSpider(scrapy.Spider): | ||
""" | ||
Finishes without a twisted.internet.error.DNSLookupError exception | ||
""" | ||
name = "caching_hostname_resolver_spider" | ||
start_urls = ["http://[::1]"] | ||
|
||
|
||
if __name__ == "__main__": | ||
process = CrawlerProcess(settings={ | ||
"RETRY_ENABLED": False, | ||
"DNS_RESOLVER": "scrapy.resolver.CachingHostnameResolver", | ||
}) | ||
process.crawl(CachingHostnameResolverSpider) | ||
process.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters