zihan meng zihan meng - 1 year ago 70
Python Question

how to use for loop to iterating url index to collect the data

I am a newbie in python. I want to write a for loop to iterate the index in order to pull the data.

Here is my code:

for i in range(-90,0):

I want index=i which from range(-90,0), however the python consider my i as a string instead of a integer.

my result give me 90 identical url :


Is there anyone can help me to solve the problem?

Thank you!

Answer Source

If you think that i variable will automatically be used in the string used to populate the list, you are wrong. It does not work that way. Use .format:

for i in range(-90,0):

See Python demo

Note that literal { and } in the format string must be doubled (see index={0}). The {0} is a placeholder for the i variable (see filter={{}}) that is the first and only argument to the method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download