python - start_request 的循环槽 CSV
问题描述
我是 Python 新手,并试图遍历一个包含两列的 CSV 文件;姓名和邮政编码:
Name of Company, 1234
最终 URL 应如下所示:
https://www.example.com/result.aspx?what=Name+of+Comapny&where=1234
我试过这样:
类 csvSpider(scrapy.Spider): 名称 = 'csv_spider'
def start_requests(self): with open('test.csv') as f: for line in f: if not line.strip(): continue print 'https://www.example.com/result.aspx?what=' + line[0] + '&where=' + line[1] yield Request('https://www.example.com/result.aspx?what=' + line[0] + '&where=' + line[1])
我还在 Python 文件的开头导入了 CSV 模块。
不知道我做错了什么 - 我怎样才能做到这一点?
提前致谢!
解决方案
推荐阅读
- excel - 用于检查重复的 Excel VBA 循环不起作用...有时
- ios - 如何隐藏 .numberPad 键盘上的字母?
- arrays - 快速比较两个数组的内容
- laravel - 强制路由到 HTTPS
- javascript - 如何自定义 angular-6-datatable 组件的 mfBootstrapPaginator
- php - 使用 AJAX 从数据库中获取值以根据另一个标签选择的选定选项选择输入
- php - 将数组插入 SQL 数据库
- jquery - jQuery事件在Windows10下的Firefox中不起作用
- php - 如何允许访问laravel中的子文件夹?
- node.js - 如何从nodejs中的两个嵌套回调函数返回数据