import requests
import bs4
import urllib.request
import urllib
import os

hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
       'Accept-Encoding': 'none',
       'Accept-Language': 'en-US,en;q=0.8',
       'Connection': 'keep-alive'}

DownPath = "C:/Users/Administrator/PycharmProjects/untitled/"

c = '.jpg'

for x in range(5, 100):

    newDownPath = DownPath + str(x) +"/"
    os.mkdir(newDownPath)
    site = "http://www.meizitu.com/a/" + str(x) + ".html"
    local_filename, headers = urllib.request.urlretrieve(site)
    html = open(local_filename)

    soup = bs4.BeautifulSoup(html,"html5lib")
    jpg = soup.find_all('img')

    PhotoNum = 0
    for photo in jpg:
        src = photo.get('src')
        print(src)

        PhotoNum += 1
        Name = (str(PhotoNum) + c)
        r = requests.get(src,headers = hdr)
        with open(newDownPath + Name, 'wb') as fd:
            for chunk in r.iter_content():
                fd.write(chunk)
        print(src)

  

【Python】下载图片的更多相关文章

  1. python下载图片超时的调查

    在使用python3下载图片时, 常用的方法有urlretrieve和requests两种, 不管哪种方法在网速极慢的情况下, 会出现图片下载卡住现象.那如何解决呢? 小编根据网上提供的资料测试了几种 ...

  2. Python下载图片并保存本地的两种方式

    一:使用Python中的urllib类中的urlretrieve()函数,直接从网上下载资源到本地,具体代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  3. python下载图片(2)

    #-*- coding: UTF-8 -*- import urllib2, re,datetime,time, os,sys from PIL import Image, ImageDraw, Im ...

  4. python 下载图片的方法

    a='http://wx1.sinaimg.cn/mw600/006HOayNgy1fqjdi2nxohj32pw3o8x6s.jpg'  #图片下载地址   ( 这里改成 文件txt地址)w='/U ...

  5. 使用python下载图片(福利)

    刚学python 没多久, 代码处处是漏洞,也希望各位大佬理解一下 爬出来的图片... 使用的 是 https://www.tianapi.com/  接口下的 美女图片... (需要自己注册一个账号 ...

  6. Python下载图片小程序

    欢迎大侠们指正批评 思路: 1.引入相关的python文件(import re  import urllib) 2.读取对应网页的html文件(使用 urllib) def getHtml(url): ...

  7. Python 下载图片的几种方法

    import osos.makedirs('./image/', exist_ok=True)IMAGE_URL = "http://image.nationalgeographic.com ...

  8. python下载图片(3)

    # -*- coding: utf-8 -*-"""some function by metaphy,2007-04-03,copyleftversion 0.2&quo ...

  9. python下载图片

    import re import  urllib.request   def getHtml(url): page = urllib.request.urlopen(url) html = page. ...

  10. python 下载图片

    import requests from PIL import Image from io import BytesIO url = 'http://image2.buslive.cn/shp/upl ...

随机推荐

  1. CentOS 6.2配置本地yum源

    转载自http://www.cnblogs.com/centoser/articles/2411694.html#undefined 一.挂载本地光盘到系统:把Cent6.2安装光盘放入光驱,在终端命 ...

  2. intellij idea rearrange code

        reformat code的时候,无法将filed放在method前边,很恶心. 那么先去

  3. 【目标检测】R-CNN系列与SPP-Net总结

    目录 1. 前言 2. R-CNN 2.0 论文链接 2.1 概述 2.2 pre-training 2.3 不同阶段正负样本的IOU阈值 2.4 关于fine-tuning 2.5 对文章的一些思考 ...

  4. 解决 ORA-28001: the password has expired 问题

    1.首先需要使用dba登录. 2.运行SQLPlus命令行工具, 输入: connect as sysdba; 3.输入dba的用户名和密码后进行 4.ALTER USER 用户名 IDENTIFIE ...

  5. IDEA 中使用 Vue 提示 namespace is not bound

    今天在 IDEA 中使用 vue.js 时提示我如下错误信息 解决方法: 把这个校验项目去掉就可以了.

  6. 在activity之间传递数据

    在activity之间传递数据 一.简介 二.通过intent传递数据 1.在需要传数据的界面调用 intent.putExtra("data1", "我是fry&quo ...

  7. java实现赋值excel模板,并在新文件中写入数据,并且下载

    /** * 生成excel并下载 */ public void exportExcel(){ File newFile = createNewFile(); //File newFile = new ...

  8. pandas 运算

    Data frame 和 series 的运算:横列相加减:按照index ,row 的方向直接相加减.frame-series纵列相加减:按照 columns,运用算术函数,相加减. frame.s ...

  9. MongoDB.Driver 2.4以上版本 在.NET中的基本操作

    MongoDB.Driver是操作mongo数据库的驱动,最近2.0以下版本已经从GitHub和Nuget中移除了,也就是说.NET Framework4.0不再能从官方获取到MongoDB的驱动了, ...

  10. C# - Generics泛型,一图话c#泛型

    一.一篇好文 https://www.cnblogs.com/yueyue184/p/5032156.html 二.一幅好图