Я сканирую веб-сайт с объявлениями о недвижимости, и «Купить / Арендовать» можно найти только на странице со списком. Я извлек другие данные со страницы сведений, проанализировав каждый URL-адрес метода parse_property из метода parse, однако я не удалось получить тип предложения с главной страницы списка.
Я пытался сделать это так же, как я анализировал отдельные URL-адреса. (Код с комментариями)
def parse(self, response):
properties = response.xpath('//div[@class="property-information-address"]/a')
for property in properties:
url= property.xpath('./@href').extract_first()
yield Request(url, callback=self.parse_property, meta={'URL':url})
# TODO: offering
# offering=response.xpath('//div[@class="property-status"]')
# for of in offerings:
# offering=of.xpath('./a/text()').extract_first()
# yield Request(offering, callback=self.parse_property, meta={'Offering':offering})
next_page=response.xpath('//div[@class="pagination"]/a/@href')[-2].extract()
yield Request(next_page, callback=self.parse)
def parse_property(self, response):
l = ItemLoader(item=NPMItem(), response=response)
url=response.meta.get('URL')
#offer=response.meta.get('Offering')
l.add_value('URL', response.url)
#l.add_value('Offering', response.offer)