私はScrapyを初めて使いました。現在、Tor darknetのフォーラムをクロールするCrawlSpiderを作成しようとしています。現在、私のCrawlSpiderコードは次のとおりです。私の治療用CrawlSpiderで相対パスを絶対パスに変換するにはどうすればよいですか?
:フォーラムは、相対パスを使用していますimport scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
class HiddenAnswersSpider(CrawlSpider):
name = 'ha'
start_urls = ['http://answerstedhctbek.onion/questions']
allowed_domains = ['http://answerstedhctbek.onion', 'answerstedhctbek.onion']
rules = (
Rule(LinkExtractor(allow=(r'answerstedhctbek.onion/\d\.\*', r'https://answerstedhctbek.onion/\d\.\*')), follow=True, process_links='makeAbsolutePath'),
Rule(LinkExtractor(allow=()), follow=True, process_links='makeAbsolutePath')
)
def makeAbsolutePath(links):
for i in range(links):
links[i] = links[i].replace("../","")
return links
ので、私は「../」私は自分のコードを実行したときしかし、私はまだrecieving午前を削除するには、カスタムprocess_linksを作成しようとしました
2017-11-11 14:46:46 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <400 http://answerstedhctbek.onion/../badges>: HTTP status code is not handled or not allowed
2017-11-11 14:46:46 [scrapy.core.engine] DEBUG: Crawled (400) <GET http://answerstedhctbek.onion/../general-guidelines> (referer: http://answerstedhctbek.onion/questions)
2017-11-11 14:46:47 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <400 http://answerstedhctbek.onion/../general-guidelines>: HTTP status code is not handled or not allowed
2017-11-11 14:46:47 [scrapy.core.engine] DEBUG: Crawled (400) <GET http://answerstedhctbek.onion/../contact-us> (referer: http://answerstedhctbek.onion/questions)
2017-11-11 14:46:47 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <400 http://answerstedhctbek.onion/../contact-us>: HTTP status code is not handled or not allowed
2017-11-11 14:46:48 [scrapy.core.engine] DEBUG: Crawled (400) <GET http://answerstedhctbek.onion/../questions?sort=hot> (referer: http://answerstedhctbek.onion/questions)
2017-11-11 14:46:48 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <400 http://answerstedhctbek.onion/../questions?sort=hot>: HTTP status code is not handled or not allowed
2017-11-11 14:46:48 [scrapy.core.engine] DEBUG: Crawled (400) <GET http://answerstedhctbek.onion/../questions?sort=votes> (referer: http://answerstedhctbek.onion/questions)
ご覧のとおり、私はまだ悪いパスのために400のエラーが発生しています。私のコードがリンクから "../"を削除しないのはなぜですか?
ありがとうございます!
Aufziehvogel、それは最終的に正しく、あなたのおかげで働いています! makeAbsolutePathのパラメータとして 'self'を追加するまで、上記のエラーを受け取れませんでした。だから、あなたが言及した他のすべての決議を含めて、「自己」を加えることはこれを解決しました。URLはまだ間違っていましたが、私は単にラインリンク[i] .url = links [i] .url.replace( '../'、 '')を含めることができました。 – ToriTompkins