简体   繁体   中英

Why is the value of i not increasing in the python code below? What should I do to increase it?

Why is the value of i not increasing in the python code below? What should I do to increase it?

i = 0
for z in analink2.iloc[i,[1]]:
    req = requests.get(z, headers = header)
    print(z)
    i += 1
analink2.head()
Out[268]: 
             section                                            weblink
0  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
1  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
2  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
3  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...
4  bilgisayar-tablet  https://www.trendyol.com/bilgisayar-tablet-x-c...

I expect the value of i to increase and the index of z to increase with i as long as z is in the loop

If you want to iterate over values in weblink column you can use next example:

for url in analink2["weblink"]:
    print(url)
    req = requests.get(url, headers=header)

If you want index value you can use for example .iterrows() :

for idx, row in analink2.iterrows():
    print(idx, row['weblink'])
    req = requests.get(row['weblink'], headers=header)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM