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. Flink快速入门

    文章目录 1 安装:下载并启动 1.1 下载 1.2 启动一个local模式的Flink集群 2 运行例子 3 集群模式安装 4 Flink on YARN 安装:下载并启动 Flink可以在Linu ...

  2. LightOJ 1341 Aladdin and the Flying Carpet(唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1341 题意:给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. 思路 ...

  3. centos mysql忘记密码

    1.停止mysql 服务:service mysqld stop; 2.vim命令打开mysql配置文件my.cnf(位置一般为:/etc/my.cnf) 3.在mysqld进程配置文件中添加skip ...

  4. 在lnmp下开启fileinfo扩展 Ubuntu系统

    在lnmp下开启fileinfo扩展 Ubuntu系统 1.进入目录下 cd /usr/local/lnmp1.4-full/src/php-5.6.31/ext/fileinfo 2.phpize处 ...

  5. yii2的定时任务

    php yii minsheng-cancel-account/cancel-applied-account

  6. phpMyAdmin 应用程序“DEFAULT WEB SITE”中的服务器错误

    分析原因:没有“C:\inetpub\wwwroot\phpmyadmin\”此目录 解决办法:新建路径 分析原因:IIS设置少了一项,需添加"服务端包含"选项 解决办法:控制面板 ...

  7. day17 Django学习三

    参考博客: http://www.cnblogs.com/wupeiqi/articles/5237704.html http://www.cnblogs.com/wupeiqi/articles/5 ...

  8. Highcharts 基本区域图;Highcharts 使用负数区域图;Highcharts 堆叠区域图;Highcharts 百分比堆叠区域图

    Highcharts 基本区域图 配置 chart chart.type 配置项用于设定图表类型,默认为 "line",本章节我们使用 'area'. var chart = { ...

  9. 使用群晖NAS:配置Git server

    1.首先在群晖的DSM的控制面板中创建一个用户例如是Git_test(我给了管理员权限) 2.在套件中心安装 Git server 3.打开Git server 勾选用户 Git_test 4.在控制 ...

  10. Partition 1 does not start on physical sector boundary.分区信息不正常

    [root@v1 ~]# df -h Filesystem      Size  Used Avail Use% Mounted on /dev/sda2        20G  3.3G   16G ...