简体   繁体   中英

How do I loop through a payload parameter in a GET Request?

My goal is to iterate through a list of zip codes to parse data from a website. Instead of enter all of these parameters; I would like to iterate through the list of zip codes

import requests 
# List of Zip Codes to Iterate through
zip_codes = ['00001', '10000', '20000', '30000', '40000', '50000', '60000', '70000', '80000', '90000']

# Need to make a loop of all the Zip Codes
payload = {
    'address': zip_codes,
    'radius': 250,
    'pagesize': 40,
    'page': 1,
}

response = requests.get(url, params=payload, headers=headers)
for zip_code in zip_codes:
    payload = {
        'address': zip_code,
        ....
    }
    response = requests.get(...)

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