나는 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
때문에, 나는 "../"내 코드를 실행하면 그러나 나는 아직도 잡 오전를 제거하기 위해 사용자 정의 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