Я пытаюсь получить данные с сайта localhost,
#scrapy shell localhost.aspx
for i in response.xpath('//*[text()="Core Units"]/parent::*/parent::*/parent::*/div'):
i.xpath('.//text()').extract()
это вывод
['Core Units']
['AB43342', 'Identify learning objectives']
['Elective Units']
['AB43343', 'Engage with texts for personal purposes']
['AB43344', 'Engage with texts for learning purposes']
['AB43345', 'Engage with texts for employment purposes']
['AB43346', 'Engage with texts to participate in the community']
['Extra Units']
['AB43348', 'Create texts for personal purposes']
['AB43349', 'Create texts for learning purposes']
['AB43350', 'Create texts for employment purposes']
Я хочу создать 1 словарь следующим образом:
di={'Core Units':['Code:AB4334 desc: Identify learning objectives'],
'Elective Units':['Code: AB43343 desc: Engage with texts for personal purposes',
'Code: AB43344 desc:Engage with texts for learning purposes',
...,]
'Extra Units': ['Code: AB43348 desc: Create texts for personal purposes',
...]
}
Я не знаю, какие ключи могут отображаться, поэтому я не могу создать пустой словарь и начать заполнять его, я должен взять их из for l oop