나는 거미가 긁는 페이지에 도착하기 전에 3 페이지를 지나는 거미를 만들고자한다. 그러나 쉘에서 응답을 테스트했지만, 함께 작동하지 않는 이유와 확실하지 않습니다. 아래거미가 링크를 따라갈 수 없다 - 치료
내 코드 :
# -*- coding: utf-8 -*-
import scrapy
class CollegiateSpider(scrapy.Spider):
name = 'Collegiate'
allowed_domains = ['collegiate-ac.com/uk-student-accommodation']
start_urls = ['http://collegiate-ac.com/uk-student-accommodation/']
# Step 1 - Get the area links
def parse(self, response):
for city in response.xpath('//*[@id="top"]/div[1]/div/div[1]/div/ul/li/a/text').extract():
yield scrapy.Request(response.urljoin("/" + city), callback = self.parse_area_page)
# Step 2 - Get the block links
def parse_area_page(self, response):
for url in response.xpath('//div[3]/div/div/div/a/@href').extract():
yield scrapy.Request(response.urljoin(url), callback=self.parse_unitpage)
# Step 3 Get the room links
def parse_unitpage(self, response):
for url in response.xpath('//*[@id="subnav"]/div/div[2]/ul/li[5]/a/@href').extract():
yield scrapy.Request(response.urljoin(final), callback=self.parse_final)
# Step 4 - Scrape the data
def parse_final(self, response):
pass
나는 this answer에 따라 Crawlspider
로 변경 시도했다, 그러나 그 도움이 될 것 같지 않았다.
나는 현재 거미를 디버깅하는 방법을 찾고 있지만, 그걸로 어려움을 겪고 있으므로 여기서도 의견을 얻는 것이 도움이 될 것이라고 생각했습니다.
output.csv
에서 최종 URL을 저장합니다. 아마도 문제를 찾는 데 도움이 될 것입니다. 'url을 올바르게 작성했는지 확인하기 위해'response.urljoin()'을 표시 할 수도 있습니다. – furas이 변수가 없다면 왜'parse_unitpage'의'response.urljoin (final)'에'final'을 사용합니까? 오류 메시지가 표시되지 않습니까? – furas
'parse()'의'xpath()'는 결과를주지 않습니다. 'div/div/div /'대신 클래스 이름을 사용할 수 있습니까? – furas