我想从本地主机网站上获取一些数据
#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']
我想创建一个字典,如下所示:
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循环中获取它们
免责声明:使用Python 3.6中的^{} 格式
下面是一些对给定信息有帮助的内容
产出:
试试这个:
相关问题 更多 >
编程相关推荐