在这里,我创建了一个我想通过函数运行的网站列表。
import requests
item_ids=[11732, 536]
url_template = 'http://www.grandexchangecentral.com/include/gecgraphjson.php?jsid=%r'
your_sites = []
for i in range(0, len(item_ids)):
result = url_template % item_ids[i]
your_sites.append(result)
棘手的部分(无论如何对我来说)是创建一个函数,该函数将每个项目放入your_sites
并通过函数对其进行迭代。我考虑过使用某种 for 循环,但我不确定如何实现它,并认为无论如何可能有更有效的方法。这是我的尝试,它返回TypeError: 'NoneType' object is not iterable
.
def data_grabber():
for i in range(0, len(your_sites)):
url = your_sites[i]
r = requests.get(url, headers={'Referer': 'www.grandexchangecentral.com'})
data = r.json
prices = [i[1] for i in data]
我希望它prices
为每个网站返回,但我的努力只能得到错误和 None 值。任何帮助将非常感激。