【Python学习】爬虫:图片下载

import urllib.request
path = "F:\\book2"
url_x = ["http://202.119.70.51:88/png/png.dll?did=a174&pid=2CE8333B97FAFFF99B24DE90BB1E63172B23EDAA889E91B34E9922EDA68B27A5574C8E34668C83EA37CDD047593787DCC32D14BD704B1EC7F13E1327A165A8B86AA5FFAA980E342ADF905CDA8899621A5D82E7E1FD4CF227DE52956C22DFF04AFC3693C137DE5B6FE1915D271EBFAFDF66A0&jid=/00000{}.jpg".format(str(i)) for i in range(0,10)]
url_xx = ["http://202.119.70.51:88/png/png.dll?did=a174&pid=2CE8333B97FAFFF99B24DE90BB1E63172B23EDAA889E91B34E9922EDA68B27A5574C8E34668C83EA37CDD047593787DCC32D14BD704B1EC7F13E1327A165A8B86AA5FFAA980E342ADF905CDA8899621A5D82E7E1FD4CF227DE52956C22DFF04AFC3693C137DE5B6FE1915D271EBFAFDF66A0&jid=/0000{}.jpg".format(str(i)) for i in range(10,100)]
url_xxx = ["http://202.119.70.51:88/png/png.dll?did=a174&pid=2CE8333B97FAFFF99B24DE90BB1E63172B23EDAA889E91B34E9922EDA68B27A5574C8E34668C83EA37CDD047593787DCC32D14BD704B1EC7F13E1327A165A8B86AA5FFAA980E342ADF905CDA8899621A5D82E7E1FD4CF227DE52956C22DFF04AFC3693C137DE5B6FE1915D271EBFAFDF66A0&jid=/000{}.jpg".format(str(i)) for i in range(100,221)]
name =["F:\\book2\\body_{}.jpg".format(str(i)) for i in range(0,221)]

headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
}

for i in range(0,10):
    conn = urllib.request.urlopen(url_x[i])
    f = open(name[i],'wb')
    f.write(conn.read())
    f.close()

print(len(url_xx))
for i in range(10,100):
    conn = urllib.request.urlopen(url_xx[i-10])
    f = open(name[i],'wb')
    f.write(conn.read())
    f.close()

print(len(url_xxx))
for i in range(100,221):
    conn = urllib.request.urlopen(url_xxx[i-100])
    f = open(name[i],'wb')
    f.write(conn.read())
    f.close()

你可能感兴趣的:(编程技术,python,学习,爬虫)