2
我正在教自己做項目的蟒蛇,我試圖請求一個API的商店位置。有6000家商店,但API一次只允許1個位置。正如你在下面的代碼中看到的那樣,效率不高。請求1-6000個URL的更有效方法是什麼?對於開始於http://www.ecommerce.com/stores?serviceTypes=-1&storeIds=1和http://www.ecommerce.com/stores?serviceTypes=-1&storeIds=6000python請求多個URL的REST API
我使用github.com/ross/requests-futures嘗試結束,但一直沒能得到的URL它的工作
import requests, json
from requests import Session
session = Session()
url = ['http://www.ecommerce.com/stores?serviceTypes=-1&storeIds=%s' % n for n in xrange(1, 6000)]
header = {
'access_token': '12341234',
'country_code': 'US',
'language_code': 'en'}
r = session.get(url, headers=header)
dump = r.text
f = open("myfile.txt", "w")
f.write(dump)
目前我得到以下錯誤:requests.exceptions.InvalidSchema:無連接適配器被發現
什麼,我基本上是試圖做的是下面的代碼:
url = "http://www.ecommerce.com/stores?serviceTypes=-1&storeIds=1"
url2 = "http://www.ecommerce.com/stores?serviceTypes=-1&storeIds=2"
url3 = "http://www.ecommerce.com/stores?serviceTypes=-1&storeIds=3"
header = {
'access_token': '12341234',
'country_code': 'US',
'language_code': 'en'}
r = requests.get(url, headers=header)
r2 = requests.get(url2, headers=header)
r3 = requests.get(url3, headers=header)
dump = r.text + r2.text + r3.text
f = open("myfile.txt", "w")
f.write(dump)