私は Python Scrapy の初心者で、学校の掲示板から投稿をクロールするための簡単なスクリプトを作成しました。ただし、スパイダーを実行すると、次のようなエラー メッセージが表示されます。
015-03-28 11:16:52+0800 [nju_spider] DEBUG: 再試行中 http://bbs.nju.edu.cn/bbstcon?board=WarAndPeace&file=M.1427299332.A> (2回失敗): [> ] 2015-03-28 11:16:52+0800 [nju_spider] DEBUG: 再試行を断念 http://bbs.nju.edu.cn/bbstcon?board=WarAndPeace&file=M.1427281812.A> (3回失敗) : [>] 2015-03-28 11:16:52+0800 [nju_spider] エラー: ダウンロード エラー http://bbs.nju.edu.cn/bbstcon?board=WarAndPeace&file=M.1427281812.A>: [> ]
2015-03-28 11:16:56+0800 [nju_spider] 情報: Scrapy 統計のダンプ: {'downloader/exception_count': 99、'downloader/exception_type_count/twisted.web._newclient.ResponseFailed': 99、'downloader/request_bytes ': 36236、'downloader/request_count': 113、'downloader/request_method_count/GET': 113、'downloader/response_bytes': 31135、'downloader/response_count': 14、'downloader/response_status_count/200': 14、'dupefilter /filtered': 25, 'finish_reason': 'finish', 'finish_time': datetime.datetime(2015, 3, 28, 3, 16, 56, 677065), 'item_scraped_count': 11, 'log_count/DEBUG': 127 、「log_count/ERROR」: 32、「log_count/INFO」: 8、'request_depth_max': 3, 'response_received_count': 14, 'スケジューラ/デキュー': 113, 'スケジューラ/デキュー/メモリ': 113, 'スケジューラ/エンキュー': 113, 'スケジューラ/エンキュー/メモリ': 113, 'start_time ': datetime.datetime(2015, 3, 28, 3, 16, 41, 874807)} 2015-03-28 11:16:56+0800 [nju_spider] 情報: スパイダーを閉じました (終了しました)
スパイダーは URL を試行して失敗したようですが、この URL は実際に存在します。また、bbs には約数千の投稿がありますが、スパイダーを実行するたびに、ランダムにいくつかの投稿しか取得できません。私のコードは次のようなものです。ご協力いただきありがとうございます
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors import LinkExtractor
from ScrapyTest.items import NjuPostItem
class NjuSpider(CrawlSpider):
name = 'nju_spider'
allowed_domains = ['bbs.nju.edu.cn']
start_urls = ['http://bbs.nju.edu.cn/bbstdoc?board=WarAndPeace']
rules = [Rule(LinkExtractor(allow=['bbstcon\?board=WarAndPeace&file=M\.\d+\.A']),
callback='parse_post'),
Rule(LinkExtractor(allow=['bbstdoc\?board=WarAndPeace&start=\d+']),
follow=True)]
def parse_post(self, response):
# self.log('A response from %s just arrived!' % response.url)
post = NjuPostItem()
post['url'] = response.url
post['title'] = 'to_do'
post['content'] = 'to_do'
return post