迭代csv reader对象以使用requests.g调用api

2024-04-29 18:59:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我有几百家公司要用api查询。 每个api url调用都在csv文件中的一列中,格式如下: http://api.duedil.com/open/search?q={“公司名称”}&api_key=xxxxxxxxxxxxx

我用csv打开并读取csv文件作为一个reader对象,但是我不知道如何通过迭代来获得每个公司的返回详细信息,例如

for row in reader:
  requests.get(row)

在一个url上运行可以很好地提供我期望的JSON数据:

^{pr2}$

抱歉,如果这是一个看似微不足道的问题,但我如何简单地迭代csv reader对象中的每个url并将其输入到请求.get在某个对象中调用的结果。 谢谢

这是什么csv.reader对象打印为:

for row in reader:

print(row)

['http://api.duedil.com/open/search?q={"Parkeon Ltd"}&api_key=xxxxxxx ']
['http://api.duedil.com/open/search?q={"M and D Foundations and Building Services Ltd"}&api_key=xxxxxxxxx ']
['http://api.duedil.com/open/search?q={"TM Lewin"}&api_key=xxxxxx ']
['http://api.duedil.com/open/search?q={"Stralfors Plc"}&api_key=xxxxxx ']
['http://api.duedil.com/open/search?q={"CPM UK Ltd"}&api_key=xxxxx ']

Tags: 文件csv对象keycomapihttpurl