Python 无法使用前一个函数的输出作为下一个函数的输入,用于抓取web内容

Python 无法使用前一个函数的输出作为下一个函数的输入,用于抓取web内容,python,list,function,loops,Python,List,Function,Loops,我有两个函数,叫做GetItemIDlist(在电子商务网站上刮取商店的所有idproduct)和GetID_image(获取图像gallary(每个产品大约8个图像)并在本地存储) 当单独运行时,它们都能顺利工作 但是我不知道如何使用函数1的输出,它给出了如下所示的产品ID列表,作为函数2中循环过程的输入 因为函数2,目前,只要给它一个特定的产品id,就可以得到图像gallary 因此,我想添加一个循环(使用函数1生成的输出列表)来获取所有产品项的所有图像,而不是手动将项id键入函数2中 功能

我有两个函数,叫做GetItemIDlist(在电子商务网站上刮取商店的所有idproduct)和GetID_image(获取图像gallary(每个产品大约8个图像)并在本地存储)

当单独运行时,它们都能顺利工作

但是我不知道如何使用函数1的输出,它给出了如下所示的产品ID列表,作为函数2中循环过程的输入

因为函数2,目前,只要给它一个特定的产品id,就可以得到图像gallary

因此,我想添加一个循环(使用函数1生成的输出列表)来获取所有产品项的所有图像,而不是手动将项id键入函数2中

功能1的输出:

1242118776
1379832161
2055592163
bla bla
1230767270
函数1的脚本:

def GetItemIDList (shopid):
    i=0
    while i<20:
        headers = {
            'User-Agent': 'Mozilla/5',
            'Referer': 'myrefererurl'
        }
        url = 'myAPIurl_pre'+str(shopid)+'myAPIurl_end'  
        r = requests.get(url, headers = headers, timeout= 5).json()
        for item in r['items']:
            itemid_list=item['itemid']
            print(itemid_list)
        i=i+1

在这种情况下,请花点时间帮助我,非常感谢

首先
get_items
返回特定店铺中可用商品id(20个商品)的列表(使用
shop_id

def get_项目(车间id):
项目列表=[]
对于范围内的(20):
resp=requests.get(
url='my\u api\u url\u pre/{}/my\u api\u url\u end'。格式(shopid)
标题={
“用户代理”:“Mozilla/5”,
“Referer”:“myrefereurl”
},
超时=5
).json()
项目=响应[“项目”]
对于项目中的项目:
item_list.append(item['itemid']))
返回项目列表
然后
save_images
在本地存储项目可用的所有图像(使用
item_id

def保存图像(项目id):
resp=requests.get(
url='pre_my_url/{}/end_my_url'。格式(项目id),
标题={
“用户代理”:“Mozilla/5”,
“Referer”:“myrefererheader”
},
超时=5
).json()
项目=响应[“项目”]
店铺id,店铺名称=商品['itemid'],商品['name']
商店图片=商品['images']
对于i,枚举(商店图片)中的图片图片id:
image=requests.get(
url='my\u front\u url/{}'。格式(图像id),
允许重定向=真
)
filename='{my_local_folder}/{}{}{}.jpg',shop_name,i)
以open(filename,'wb')作为文件
file.write(image.content)
最后,尝试循环浏览商店中的商品列表,并将其图像存储在本地

item\u list=get\u产品(一些店铺ID)
对于项目列表中的项目id:
保存图像(项目id)

注意,您的第一个函数
GetItemIDList
没有返回任何内容。所以它不能用输入来输入你的第二个函数…考虑在你的第一个函数中添加<代码>返回ItIDIDList。是的,我明白了。谢谢你的建议
def GetID_Image(item_id):
    headers = {
        'User-Agent': 'Mozilla/5',
        'Referer': 'myrefererheader'
    }   
    url = 'pre_myurl'+item_id+'end_myurl'
    r = requests.get(url, headers = headers, timeout= 5).json()
    itemid_shop=r['item']['itemid']
    itemname_shop=r['item']['name']
    print(itemname_shop)
    itemimage_shop=r['item']['images']
    endtag_image=range (11) #range(len(list(itemimage_shop))
    for imageid,i in zip(itemimage_shop,endtag_image):
        image_fronturl="myfronturl"
        image_fullurl=image_fronturl+imageid
        myfile = requests.get(image_fullurl, allow_redirects=True)
        open('mylocalfolder'+itemname_shop+'_'+str(i)+'.jpg', 'wb').write(myfile.content)