0

I would like to access multiple pages through this API. Each page has the same URL except for the market_id. I would like to loop through the pages based on the market_id using the specified range.

for marketid in range(1.166871138,1.171064031):
    r = requests.get('https://betfair-data-supplier-prod.herokuapp.com/api/race_results/?market_id={marketid}&nz_tote_event_id=', headers={'User-Agent': 'Mozilla/5.0'}) 

When I use this code I get an error saying 'float' object cannot be interpreted as an integer.

2 Answers2

0

If you want to use those float objects as the range for the for loop, you need to convert them into integers and iterate through those.

start = 1.166871138
stop = 1.171064031
step = 0.0001

startDecimals = len(str(start).split('.')[1]) # Get number of Decimal Points
endDecimals = len(str(stop).split('.')[1])
stepDecimals = len(str(step).split('.')[1])

maxDecimals = max(startDecimals, endDecimals, stepDecimals) # Which number has the most decimal points

# Go through them as integers
for i in range(int(start * 10**maxDecimals), int(stop * 10 **maxDecimals), int(step * 10**maxDecimals)):
    i =/(10 ** maxDecimals)
    print(i) # You can use this as the iterator value then
Bhavye Mathur
  • 1,024
  • 1
  • 7
  • 25
0

range() only accepts values as int, however you can enter your enter you range as a multiplied by 10 to the power of something, so that the result will be int then for each round of loop divide marketid by the same power of 10.

for instance: 1.166871138*(10**9)=1166871138

as a result,your code might look like this:

for marketid in range(1166871138, 1171064031):
   marketid/=10**9
   r = requests.get('https://betfair-data-supplier-prod.herokuapp.com/api/race_results/? 
   market_id={marketid}&nz_tote_event_id=', headers={'User-Agent': 'Mozilla/5.0'})