Не уверен, что это из-за форматирования, но вы увеличиваете значение на 20 в списках l oop. В любом случае, я бы попытался не адаптировать переменную класса следующим образом.
Для меня лучше сработало следующее:
import scrapy
class DaftieSpiderSpider(scrapy.Spider):
name = 'daftie_spider'
page_number = 20
allowed_domains = ['daft.ie']
start_urls = ['https://www.daft.ie/dublin-city/property-for-sale/dublin-4/']
def parse(self, response):
offset = response.meta.get('offset', 0)
listings = response.xpath('//div[@class="PropertyCardContainer__container"]')
for listing in listings:
price = listing.xpath('.//a/strong[@class="PropertyInformationCommonStyles__costAmountCopy"]/text()').extract_first()
address = listing.xpath('.//*[@class="PropertyInformationCommonStyles__addressCopy--link"]/text()').extract_first()
bedrooms = listing.xpath('.//*[@class="QuickPropertyDetails__iconCopy"]/text()').extract_first()
bathrooms = listing.xpath('.//*[@class="QuickPropertyDetails__iconCopy--WithBorder"]/text()').extract_first()
prop_type = listing.xpath('.//*[@class="QuickPropertyDetails__propertyType"]/text()').extract_first()
agent = listing.xpath('.//div[@class="BrandedHeader__agentLogoContainer"]/img/@alt').extract_first()
yield{'price': price,
'address': address,
'bedrooms': bedrooms,
'bathrooms': bathrooms,
'prop_type': prop_type,
'agent': agent}
if offset <= 180:
offset += 20
next_page = 'https://www.daft.ie/dublin-city/property-for-sale' \
'/dublin-4/?offset=' + str(offset)
yield response.follow(next_page,
callback=self.parse,
meta={'offset': offset})