-
Notifications
You must be signed in to change notification settings - Fork 218
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 #43 from sibiryakov/persistent-meta-cb
Persistent .meta and callbacks in Frontera backend
- Loading branch information
Showing
18 changed files
with
282 additions
and
77 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 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
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
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
Empty file.
Empty file.
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,14 @@ | ||
#-------------------------------------------------------- | ||
# Frontier | ||
#-------------------------------------------------------- | ||
BACKEND = 'frontera.contrib.backends.memory.FIFO' | ||
MAX_REQUESTS = 5 | ||
MAX_NEXT_REQUESTS = 1 | ||
|
||
#-------------------------------------------------------- | ||
# Logging | ||
#-------------------------------------------------------- | ||
LOGGING_EVENTS_ENABLED = False | ||
LOGGING_MANAGER_ENABLED = False | ||
LOGGING_BACKEND_ENABLED = False | ||
LOGGING_DEBUGGING_ENABLED = False |
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,39 @@ | ||
#-------------------------------------------------------------------------- | ||
# Scrapy Settings | ||
#-------------------------------------------------------------------------- | ||
BOT_NAME = 'scrapy_spider' | ||
|
||
SPIDER_MODULES = ['frontera.tests.scrapy_spider.spiders'] | ||
NEWSPIDER_MODULE = 'frontera.tests.scrapy_spider.spiders' | ||
|
||
HTTPCACHE_ENABLED = False | ||
REDIRECT_ENABLED = True | ||
COOKIES_ENABLED = False | ||
DOWNLOAD_TIMEOUT = 20 | ||
RETRY_ENABLED = False | ||
|
||
CONCURRENT_REQUESTS = 10 | ||
CONCURRENT_REQUESTS_PER_DOMAIN = 2 | ||
|
||
LOGSTATS_INTERVAL = 10 | ||
|
||
SPIDER_MIDDLEWARES = {} | ||
DOWNLOADER_MIDDLEWARES = {} | ||
|
||
#-------------------------------------------------------------------------- | ||
# Frontier Settings | ||
#-------------------------------------------------------------------------- | ||
SPIDER_MIDDLEWARES.update( | ||
{'frontera.contrib.scrapy.middlewares.schedulers.SchedulerSpiderMiddleware': 999}, | ||
) | ||
DOWNLOADER_MIDDLEWARES.update( | ||
{'frontera.contrib.scrapy.middlewares.schedulers.SchedulerDownloaderMiddleware': 999} | ||
) | ||
SCHEDULER = 'frontera.contrib.scrapy.schedulers.frontier.FronteraScheduler' | ||
FRONTERA_SETTINGS = 'frontera.tests.scrapy_spider.frontera.settings' | ||
|
||
|
||
#-------------------------------------------------------------------------- | ||
# Testing | ||
#-------------------------------------------------------------------------- | ||
#CLOSESPIDER_PAGECOUNT = 1 |
Empty file.
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,35 @@ | ||
from scrapy.contrib.linkextractors.lxmlhtml import LxmlLinkExtractor | ||
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor | ||
from scrapy.contrib.linkextractors.regex import RegexLinkExtractor | ||
from scrapy.contrib.spiders import CrawlSpider, Rule | ||
|
||
|
||
class FallbackLinkExtractor(object): | ||
def __init__(self, extractors): | ||
self.extractors = extractors | ||
|
||
def extract_links(self, response): | ||
for lx in self.extractors: | ||
links = lx.extract_links(response) | ||
return links | ||
|
||
|
||
class MySpider(CrawlSpider): | ||
name = 'example' | ||
start_urls = ['http://scrapinghub.com'] | ||
callback_calls = 0 | ||
|
||
rules = [Rule(FallbackLinkExtractor([ | ||
LxmlLinkExtractor(), | ||
SgmlLinkExtractor(), | ||
RegexLinkExtractor(), | ||
]), callback='parse_page', follow=True)] | ||
|
||
def parse_page(self, response): | ||
self.callback_calls += 1 | ||
pass | ||
|
||
def parse_nothing(self, response): | ||
pass | ||
|
||
parse_start_url = parse_nothing |
Oops, something went wrong.