xingtai -斗罗大陆图片下载

import requests
import re
import os
key = "变形金刚"
os.mkdir(key)
url = "http://image.baidu.com/search/flip?tn=baiduimage&" \
      "ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&" \
      "sf=1&fmq=1497491098685_R&pv=&ic=0&nc=1&z=&se=1&" \
      "showtab=0&fb=0&width=&height=&face=0&istype=2&" \
      "ie=utf-8&ctd=1497491098685%5E00_1519X735&word="+key
tu_pian_wang_ye = requests.get(url)

# print(tu_pian_wang_ye.text)

# 1.提取所有的图片网址
dldl = re.findall('"objURL":"(.*?)",',tu_pian_wang_ye.text)

# 打印出列表里的内容
jstm = 0
for i in dldl:
    pc = requests.get(i)

    jstm = jstm+1
    print("--------------正在下载第%d张图片---------------" % jstm)

    # 新建文件
    f = open("%s/text%d.jpg"%(key,jstm), "wb")
    # 写入内容
    f.write(pc.content)
    # 关闭文件
    f.close()





# 200   404  403

你可能感兴趣的:(学生作品,xingtai,python)