簡単に変更できるシンプルなScrapyCrawlSpiderスクリプトを作成しようとしていますが、リンクエクストラクタのルールを正しく機能させる方法がわかりません。
これが私のコードです:
class LernaSpider(CrawlSpider):
"""Our ad-hoc spider"""
name = "lerna"
def __init__(self, url, allow_follow='.*', deny_follow='', allow_extraction='.*', deny_extraction=''):
parsed_url = urlparse(url)
domain = str(parsed_url.netloc)
self.allowed_domains = [domain]
self.start_urls = [url]
self.rules = (
# Extract links
# and follow links from them (since no callback means follow=True by default).
Rule(SgmlLinkExtractor(allow=(allow_follow, ), deny=(deny_follow, ))),
# Extract links and parse them with the spider's method parse_item
Rule(SgmlLinkExtractor(allow=(allow_extraction, ), deny=(deny_extraction, )), callback='parse_item'),
)
super(LernaSpider, self).__init__()
def parse_item(self, response):
print 'Crawling... %s' % response.url
# more stuff here
私はこのコードを持っていますが、許可/拒否ルールを正しく機能させることができず、その理由がわかりません。空の文字列を残すと、すべてが拒否されますか?REだったので、「。*」などを入力した場合にのみ、全面的な拒否が行われると思いました。
どんな助けでもいただければ幸いです。