早睡早起,方能养生
Sleep early rise early, way to keep healthy

Python下载远程图片

2022-12-14 11:58
views 1601

import platform
import requests
import os

img_str = "//media.digikey.com/Renders/Power%20Integrations%20Renders/SO-8C.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/LNK584GG-TL.jpg===//media.digikey.com/Renders/STMicro%20Renders/497~8SOIC-3.9~~8.jpg===//media.digikey.com/Renders/Rohm%20Renders/Rohm-8-SOP-J.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/596;PI-4015;G;7.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/TOP266KG.jpg===//media.digikey.com/photos/Power%20Integrations%20Photos/596-8-BSMD.jpg===//media.digikey.com/Renders/Power%20Integrations%20Renders/596;PI-3933;P;7.JPG===//media.digikey.com/Renders/Power%20Integrations%20Renders/596;-PI-8106;-;-17.jpg===//media.digikey.com/Renders/Power%20Integrations%20Renders/596;PI-2551;P;7.jpg===//media.digikey.com/Renders/~~Pkg.Case%20or%20Series/8-DIP.jpg===//media.digikey.com/Renders/Power%20Integrations%20Renders/eSIP-7C.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/MFG_16-PowerSOIC-15-Leads.jpg===//media.digikey.com/photos/Power%20Integrations%20Photos/MFG_TOP255YN.jpg===//media.digikey.com/Renders/Silicon%20Labs%20Renders/8-SMD.jpg===//media.digikey.com/photos/Power%20Integrations%20Photos/596-TO-220-7C.jpg===//media.digikey.com/photos/Power%20Integrations%20Photos/MFG_TOP256YN.jpg===//media.digikey.com/Renders/Microchip%20Tech%20Renders/150;C04-034;AB;3.jpg===//media.digikey.com/Renders/Power%20Integrations%20Renders/TO-263-7C.jpg===//media.digikey.com/Renders/Linear%20Tech%20Renders/161;-05-08-1667;-MSE;-16.jpg===//media.digikey.com/Renders/Linear%20Tech%20Renders/161;-05-08-1640;-G;-20.jpg===//media.digikey.com/Renders/Diodes%20Renders/31;-SOT26;-K,-W;-6-Top.jpg===//media.digikey.com/Renders/Diodes%20Renders/8-SOIC,%207%20leads.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/488;318G-02;SN,DT;6.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/488~751-07~R,D,DF,S,ESA,D1,DR~8.JPG===//media.digikey.com/Renders/NXP%20Semi%20Renders/7-SOIC.jpg===//media.digikey.com/Renders/Fairchild%20Semi%20Renders/261;MKT-M08A;M,D,TF;8.jpg===//media.digikey.com/Renders/Monolithic%20Power%20Systems/1589;TSOT23-5;;5.jpg===//media.digikey.com/Renders/Microchip%20Tech%20Renders/8-SOIC_751.jpg===//media.digikey.com/Renders/Diodes%20Renders/SOT223-3L.jpg===//media.digikey.com/Renders/~~Pkg.Case%20or%20Series/8-SOIC.jpg===//media.digikey.com/Photos/On%20Semi%20Photos/MFG_NCP13992AxDR2G.jpg===//media.digikey.com/Renders/Maxim%20Renders/Maxim-16-TQFN.jpg===//media.digikey.com/Renders/Maxim%20Renders/8-SOIC%20Exp%20Pad%2021-0111.jpg===//media.digikey.com/Renders/Power%20Integrations%20Renders/TOPSwitch-JX-12-eDIP.jpg===//media.digikey.com/Renders/STMicro%20Renders/VIPERPLUS-8DIP.jpg===//media.digikey.com/photos/Fairchild%20Semi%20Photos/261-8-DIP,%207%20lead.jpg===//media.digikey.com/photos/Power%20Integrations%20Photos/MFG_TOP254YN.jpg===//media.digikey.com/Renders/Infineon%20Renders/448;P_PG-DIP-8;;8.jpg===//media.digikey.com/Renders/Infineon%20Renders/8-DIP;%207%20Leads.jpg===//media.digikey.com/Renders/Sanken%20Renders/1261;8DIP-7.62;;7.jpg===//media.digikey.com/Photos/Rochester/MFG_NCP1126AP100G.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/TOP223YN.JPG===//media.digikey.com/Renders/Rohm%20Renders/846;-EX001-0089;-T;-6.jpg===//media.digikey.com/Renders/Diodes%20Renders/SOT-23-6%20PKG.jpg===//media.digikey.com/Renders/Dialog%20Semi%20Renders/1564;-10SOIC-fused-3.9;-;-10.jpg===//media.digikey.com/Renders/Infineon%20Renders/8-SOIC.jpg===//media.digikey.com/Renders/Monolithic%20Power%20Systems/1589~8SOIC-7A-3,9~S~7.JPG===//media.digikey.com/Renders/Texas%20Instr%20Renders/296~4073329~DGK~8.JPG===//media.digikey.com/Photos/Osram%20Opto%20Photos/MFG_PG-DSO-16%5E12.jpg===//media.digikey.com/Renders/STMicro%20Renders/497~16SOIC-3,9~D~16.jpg===//media.digikey.com/Renders/Texas%20Instr%20Renders/8-SOIC.jpg===//media.digikey.com/Renders/~~Pkg.Case%20or%20Series/16%20SOIC.jpg===//media.digikey.com/Photos/Fairchild%20Semi%20Photos/488;MKT-TO220B04-Forming;;4.jpg===//media.digikey.com/Photos/Fairchild%20Semi%20Photos/KA78RxxC-Series-Through-Hole.jpg===//media.digikey.com/Renders/Monolithic%20Power%20Systems/1589;8PDIP-7.62;;8.jpg===//media.digikey.com/Renders/Maxim%20Renders/175;21-0664;TC;12.jpg===//media.digikey.com/Photos/Fairchild%20Semi%20Photos/9-SIP%20Formed%20Leads.JPG===//media.digikey.com/Renders/Texas%20Instr%20Renders/296~4221009~DW~16.jpg===//media.digikey.com/Renders/~~Pkg.Case%20or%20Series/28-SOIC.jpg===//media.digikey.com/photos/Texas%20Instr%20Photos/296-20-DIP.jpg===//media.digikey.com/photos/Texas%20Instr%20Photos/296-28-SOIC.jpg===//media.digikey.com/Renders/Monolithic%20Power%20Systems/1589~8SOIC-3.9~S~8.jpg===//media.digikey.com/Renders/Rohm%20Renders/846~8SOP-3,9~F~8.JPG===//media.digikey.com/Photos/Rohm%20Photos/Rohm-8-SOP.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/488~626A~P~7.jpg===//media.digikey.com/renders/Dialog%20Semi%20Renders/1695;7PDIP-7.62;;7.jpg===//media.digikey.com/Photos/Rochester/MFG_TC254P.jpg.jpg===//media.digikey.com/Renders/Texas%20Instr%20Renders/296~4221848~PW~8.JPG===-===//media.digikey.com/Renders/Analog%20Devices%20Renders/505~05-08-1510~N,-N8~8-Top.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/488;751U;;7.jpg===//media.digikey.com/Renders/NXP%20Semi%20Renders/568;SOT96-1;%20D,S,T,TN2;8.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/488~751BP~D~9.JPG===//media.digikey.com/Renders/Intersil%20Renders/8-SOIC,M8.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/10-MSOP.jpg===//media.digikey.com/Renders/Diodes%20Renders/31;-8SO-3.9;-;-8.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/MFG_INN307xM-H606.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/MFG_InnoSwitch.jpg===//media.digikey.com/Renders/Rohm%20Renders/Rohm-7-SOP.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/488~751B-05~D,-VD,-FD~16.JPG===//media.digikey.com/Renders/On%20Semi%20Renders/488;-751AM-01;-D;-15.jpg===//media.digikey.com/Renders/Monolithic%20Power%20Systems/1589~16SOIC-3.9~~16.JPG===//media.digikey.com/Photos/STMicro%20Photos/VIPER06XN.JPG===//media.digikey.com/Renders/~~Pkg.Case%20or%20Series/24-QFN%20Exposed%20Pad.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/MFG_TNY175PN.jpg===//media.digikey.com/Photos/Power%20Integrations%20Photos/TNY180PN.jpg===//media.digikey.com/photos/Power%20Integrations%20Photos/MFG_TOP257YN.jpg===//media.digikey.com/Renders/On%20Semi%20Renders/488~948BW~~12.jpg===//media.digikey.com/photos/Power%20Integrations%20Photos/TOP261YN.JPG===//media.digikey.com/Photos/Rohm%20Photos/MFG_BM2SC12xFP2-LBZE2series.jpg===//media.digikey.com/Renders/~~Pkg.Case%20or%20Series/SOT25.jpg===//media.digikey.com/Renders/Freemont%20Micro%20Devices%20Renders/SC-74A,%20SOT-753%20PKG.jpg===//media.digikey.com/Renders/~~Pkg.Case%20or%20Series/SC-74,%20SOT-457.jpg===//media.digikey.com/Renders/Power%20Integrations%20Renders/596;PI-7468;S;6.jpg===//media.digikey.com/Photos/Diodes%20Photos/MFG_AP3128S-13.jpg===//media.digikey.com/Renders/Microchip%20Tech%20Renders/150~C04-1278~EKA~7.JPG===//media.digikey.com/Renders/Diodes%20Renders/31~10SO-TypeA1~~10.JPG"

img_array = img_str.split("===")

# print(img_array);

for img in img_array:
    # print(img)

    if img == '-':
        continue

    # 获取原图片的文件名

    img_info_array = img.split("/")

    local_img_path = './1/' + img_info_array[-1]

    # 判断文件是否存在避免重复执行
    if os.path.exists(local_img_path):
        continue

    # 下载图片
    url = "https:" + img
    r = requests.get(url)

    # 写入图片
    with open(local_img_path, "wb") as f:
        f.write(r.content)

    print(local_img_path, "=========>下载成功!") #, platform.python_version()

 



分享
0 条讨论
top