일부 시작 URL을 긁어 내고 규칙에 따라 해당 페이지의 링크를 따라야합니다. 내 거미는 CrawlSpider
에서 물려 받았으며 start_urls
이고 '규칙'이 설정되어 있습니다. 하지만 start_urls를 구문 분석하기 위해 정의한 구문 분석 함수를 사용하지 않는 것 같습니다. 여기 코드는 다음과 같습니다어떤 구문 분석 방법을 사용하여 start_urls를 구문 분석 했습니까?
<!-- language: lang-python -->
class ZhihuSpider(CrawlSpider):
start_urls = ["https://www.zhihu.com/topic/19778317/organize/entire",
"https://www.zhihu.com/topic/19778287/organize/entire"]
rules = (Rule(LinkExtractor(allow= (r'topic/\d+/organize/entire')), \
process_request='request_tagInfoPage', callback = 'parse_tagPage'))
# this is the parse_tagPage() scrapy should use to scrape
def parse_tagPage():
print("start scraping!") # Explicitly print to show that scraping starts
# do_something
그러나, 콘솔이 scrapy가 start_urls 크롤링하지만 아무것도 인쇄되지 것을 보여줍니다. 그래서 parse_tagPage() 함수가 호출되지 않았 음을 확신합니다. 비록 치료에도 URL이 크롤링됨을 보여줍니다. [scrapy] DEBUG: Crawled (200) <GET https://www.zhihu.com/topic/19778317/organize/entire> (referer: http://www.zhihu.com)
parse_tagPage()를 사용하기 위해 치료법을 설정하는 방법에 대한 힌트가 있습니까?
start_urls를 언급 할 때 문서에서 start_request() 메서드를 사용하여 해당 URL을 방문한 다음 언급 한 규칙과 일치하는지 확인한 후 규칙과 일치하면 parse_tagPage() 메서드를 방문합니다. else는 아무 것도하지 않습니다 (일치하는 규칙이 없을 때 기본 콜백 메소드를 정의 할 수 있습니다) http://doc.scrapy.org/en/latest/topics/spiders.html?highlight=start%20request#scrapy.spiders.Spider .start_requests – MrPandav
자신 만의 질문에 대답 한 다음 대답으로 질문을 편집하는 대신 대답을 수락 할 수 있습니다. –
감사합니다! 그걸 몰랐어. – Skywalker326