python - Extract() 位置列表
问题描述
嗨,我尝试从scrapy 项目中提取信息。
我试试
dre = [i.split(', ') for i in response.xpath('normalize-space(//*[contains(@class,"business-address")])').extract()]
ml_item['address'] = dre[0]
输出:
'address': ['Calle V Centenario 24', '46900', 'Torrente', 'Valencia']
我需要将此输出中的信息保存在以逗号分隔的不同变量中
ml_item['cp'] = '46900'
,ml_item['city'] = 'Torrente'
解决方案
如果dre[0]
给你['Calle V Centenario 24', '46900', 'Torrente', 'Valencia']
那么
ml_item['cp'] = dre[0][1]
ml_item['city'] = dre[0][2]
或者
ml_item['address'] = dre[0]
ml_item['cp'] = ml_item['address'][1]
ml_item['city'] = ml_item['address'][2]
推荐阅读
- javascript - 如何将分割的 INSIDE 边框应用于视频元素?
- python - 链接 __getitem__ (d['a']['b']) 不适用于自定义 dict 包装器
- python - 如何在数据框函数的不同列上同时使用 sum 和 count 函数?
- css - 将 ngx-bootstrap-multiselect 的每个选项放在自己的行上的正确方法是什么?
- python - 尝试连接数据库和 Web 容器时 SQL Alchemy 连接被拒绝
- c++ - c++ 的反向代理
- go - 在文件保存期间扫描整个文件夹
- java - Android Kotlin 在第二个 Activity 中获取 BackStack 的计数
- nginx - Nginx 返回标头指示缓存状态
- python - 创建一个自我更新的分数