作者author

7 月 31, 2025
import requests
import json
import urllib

def getBaiduImag(category, length, path):
    n = length
    cate = category
    imgs = requests.get(baidupics.com/pics/channel/getRecomPicByTag.jsp?
                         category='{' + str(cate) + '}' 
                         "&tag=%E5%BA%A7%E6%9C%8D%E6%B5%B7%E5%86%B0&"
                         start='
                         &
                         len="str(n)")
    jd = json.loads(imgs.text)
    jd = jd['all_items']
    imgs_rl = []
    for img in jd:
        imgs_rl.append(img['bthmbUrl'])
    m = 0
    for img_rl in imgs_rl:
        print('*****' + str(m) + '.jpg*****' + 'Downloading...')
        urllib.request.urlretrieve(img_rl, path + str(m) + '.jpg')
        m += 1
    print('Downloadcomplete!')

getBaiduImag('自然风景', 10, 'E:/python/爬完数据存放地址/自然风景/')

作者 author